Routing is written in main.nim
. it is the entrypoint file of Basolato.
Routing of Basolato is exactory the same as Jester
, although you can call controller method by route()
import basolato/routing
import app/controllers/SomeController
routes:
get "/":
route(newSomeController(request).index())
post "/":
route(newSomeController(request).create())
get "/@id":
route(newSomeController(request).show(@"id"))
Table of Contents
Following HTTP Verbs are valid.
verb | explanation |
---|---|
get | Gets list of resources. |
post | Creates new resource. |
put | Updates single resource. |
patch | Updates single resource. |
delete | Deletes single resource. |
head | Gets the same response but without response body. |
options | Gets list of response headers before post/put/patch/delete/ access by client API software such as Axios/JavaScript and Curl/sh. |
trace | Performs a message loop-back test along the path to the target resource, providing a useful debugging mechanism. |
connect | Starts two-way communications with the requested resource. It can be used to open a tunnel. |
error | Catch exception or HttpCode |
before | Run before get/post/put/patch/delete access. |
after | Run after get/post/put/patch/delete access. |
This functions is definded in jester
router dashboard:
get "/url1":
route(newDashboardController(request).url1())
get "/url2":
route(newDashboardController(request).url2())
routes:
extend dashboard, "/dashboard"
/dashboard/url1
and /dashboard/url2
are available.
response(result)
return a instance of Response
. This has some fields.
after re"/api.*":
echo response(result).body
echo response(result).headers
echo response(result).status
extend api, "/api"