logo
首页技术栈工具库讨论
nested-routes

nested-routes

A method to writing Wai responses This library attempts to make it easier to write nice Wai response handlers by giving us a Sinatra/ Scotty-like syntax for declaring HTTP-verb oriented routes, in addition to file-extension handling and rose-tree like composition. Not only do we have literal route specification, like Scotty & Spock, but we can also embed Attoparsec parsers and Regular Expressions directly in our routes, with our handlers reflecting their results. You can find more information on the demo. As an example: The route specification syntax is a little strange right now - l specifies a literal chunk of a handlable url (ie - l "foo" </> l "bar" </> o would represent the url /foo/bar), while p represents a parsable url chunk, which expects a pair - the left element being merely a reference name for the parser during internal plumbing, and the right being the actual Parser. o represents the end of a url string, and can be used alone in a handler to capture requests to the root path. Each route being handled needs some kind of content. For every parsed url chunk, the route expects a function of arity matching 1-for-1 with the parsed contents. For example, d -> ... in the demonstration above is such a function, where d :: Double. Internally, we match against both the file extension and Accept headers in the HTTP request - the Accept header may override the file extension. When we test our application: requests may end with index and specify the file extension each responding with the closest available file type
由 
bruceshi2021-01-13 收录
--
推荐
不推荐
更多信息
HACKAGE
carbal install nested-routes
查看
标签
根据用户添加的标签生成
暂无标签