myway

https://github.com/fukamachi/myway.git

git clone 'https://github.com/fukamachi/myway.git'

(ql:quickload :myway)
2

My Way

My Way is a Sinatra-compatible URL routing library. This was originally written as Clack.Util.Route, a part of Clack.

Usage

(use-package :myway)

(defvar *mapper* (make-mapper))

(connect *mapper* "/" "Welcome to My Way.")

(connect *mapper* "/hello/?:name?"
         (lambda (params)
           (format nil "Hello, ~A" (or (getf params :name)
                                       "Guest"))))

(dispatch *mapper* "/")
;=> "Welcome to My Way."
;   T

(dispatch *mapper* "/hello")
;=> "Hello, Guest"
;   T

(dispatch *mapper* "/hello/Eitaro")
;=> "Hello, Eitaro"
;   T

(dispatch *mapper* "/hello/Eitaro" :method :POST)
;=> NIL
;   NIL

next-route

(connect *mapper* "/guess/:who"
         (lambda (params)
           (if (string= (getf params :who) "Eitaro")
               "You got me!"
               (next-route))))

(connect *mapper* "/guess/*"
         (lambda (params)
           (declare (ignore params))
           "You missed!"))

to-app

to-app makes a Clack app from mapper.

(to-app *mapper*)
;=> #<CLOSURE (LAMBDA (MYWAY::ENV) :IN TO-APP) {100E24F13B}>

(clack:clackup (to-app *mapper*))

Installation

(ql:quickload :myway)

Author

Copyright

Copyright (c) 2014 Eitaro Fukamachi (e.arrows@gmail.com)

License

Licensed under the LLGPL License.