Huncentoot
Huncentoot是一个http server.
; SLIME 2015-12-13
CL-USER> (ql:quickload "hunchentoot")
To load "hunchentoot":
Load 1 ASDF system:
hunchentoot
; Loading "hunchentoot"
.............
("hunchentoot")
CL-USER> (hunchentoot:start (make-instance 'hunchentoot:easy-acceptor :port 4242))
CL-USER> (hunchentoot:define-easy-handler (say-yo :uri "/yo") (name)
(setf (hunchentoot:content-type*) "text/plain")
(format nil "Hey~@[ ~A~]!" name))
SAY-YO
CL-USER>
现在lisp的http服务已经启动了,点击下面地址访问看看
http://127.0.0.1:4242/yo?name=Dude
Clack
lisp有很多http server真眼花缭乱,现在有了这个clack可以把各种http服务统一到一个框架里来.clack是一个抽象层,下层可以使用各种http服务实现.
CL-USER> (ql:quickload :clack)
To load "clack":
Load 1 ASDF system:
clack
; Loading "clack"
....
(:CLACK)
CL-USER> (clack:clackup
(lambda (env)
'(200
(:content-type "text/plain")
("Hello, Clack!"))))
; in:
; CLACK:CLACKUP (LAMBDA (ENV)
; '(200 (:CONTENT-TYPE "text/plain") ("Hello, Clack!")))
; (LAMBDA (ENV) '(200 (:CONTENT-TYPE "text/plain") ("Hello, Clack!")))
;
; caught STYLE-WARNING:
; The variable ENV is defined but never used.
;
; compilation unit finished
; caught 1 STYLE-WARNING condition
To load "lack-middleware-backtrace":
Load 1 ASDF system:
lack-middleware-backtrace
; Loading "lack-middleware-backtrace"
To load "clack-handler-hunchentoot":
Load 1 ASDF system:
clack-handler-hunchentoot
; Loading "clack-handler-hunchentoot"
.............
Hunchentoot server is started.
Listening on localhost:5000.
#S(CLACK.HANDLER::HANDLER
:SERVER :HUNCHENTOOT
:ACCEPTOR #<SB-THREAD:THREAD "clack-handler-hunchentoot" RUNNING
{1005AA5313}>)
CL-USER>
点击下面连接,看看效果
http://localhost:5000/
Caveman2
这是一个web应用开发框架.首先安装下面几个asdf system,
(ql:quickload :envy)
(ql:quickload :datafly)
(ql:quickload :caveman2)
创建一个web应用
(caveman2:make-project #P"~/common-lisp/myapp/" :author "www")
载入刚刚创建的web应用,并启动:
(require "myapp")
(myapp:start :port 8080)
点击下面链接
http://localhost:8080
到此把整个http开发的框架架好了.
活在lisp里
启动web应用
CL-USER> (require :myapp)
;;; Computing Hangul syllable names
("SB-ROTATE-BYTE" "IRONCLAD" "ITERATE")
CL-USER> (myapp:start :port 8080)
To load "myapp":
Load 1 ASDF system:
myapp
; Loading "myapp"
To load "lack-middleware-accesslog":
Load 1 ASDF system:
lack-middleware-accesslog
; Loading "lack-middleware-accesslog"
To load "lack-middleware-session":
Load 1 ASDF system:
lack-middleware-session
; Loading "lack-middleware-session"
To load "lack-middleware-static":
Load 1 ASDF system:
lack-middleware-static
; Loading "lack-middleware-static"
To load "lack-middleware-backtrace":
Load 1 ASDF system:
lack-middleware-backtrace
; Loading "lack-middleware-backtrace"
To load "clack-handler-hunchentoot":
Load 1 ASDF system:
clack-handler-hunchentoot
; Loading "clack-handler-hunchentoot"
..
Hunchentoot server is started.
Listening on localhost:8080.
#S(CLACK.HANDLER::HANDLER
:SERVER :HUNCHENTOOT
:ACCEPTOR #<SB-THREAD:THREAD "clack-handler-hunchentoot" RUNNING
{1009D62123}>)
CL-USER>
进入web
CL-USER> (in-package :myapp.web)
#<PACKAGE "MYAPP.WEB">
创建一个路由
(defroute "/welcome" (&key (|name| "Guest")) (format nil "Welcome, ~A" |name|))
点击
http://localhost:8080/hello
参考的资源
Is it feasible to do (serious) web development in Lisp?
http://*.com/questions/556456/is-it-feasible-to-do-serious-web-development-in-lisp
Best web framework in Common-lisp?
http://*.com/questions/540953/best-web-framework-in-common-lisp
lisp不缺乏共享资源,下面是http开发能用到的http服务器:
s-http-server ;;https://github.com/svenvc/s-http-server
ucw.httpd ;;https://github.com/erikg/ucw-core
woo ;;https://github.com/fukamachi/woo
portableAserve ;;http://franz.com/support/documentation/current/doc/aserve/aserve.html
Hunchentoot ;;http://weitz.de/hunchentoot/
cl-http ;;访问不了主站