Hello:
I would like to divide my rest api project with jester into different src files:
- Ex:
- main.nim
import jester, asyncdispatch
routes:
- get "/":
- resp """ {"status": "ok"} """, "application/json"
- another_part.nim
import jester, asyncdispatch
routes:
- get "/anotherpart":
- resp """ {"status": "ok"} """, "application/json"
How can i achieve something like that?
Hello OderWat:
Excellent answer-solution. I didn't knew about the include statement. very nice feature for not overcomplicating macros. Thansk for your help.
include doesn't work because you can't separate the statements of the macro, thanks anyway for your help, let's see what else can i do.
It throws an error undeclared identifier: 'post'
post.inc
# Post
# *********************************************
post "/":
var current_uuid: Tuuid
resp """{"result": "ok"}""", "application/json"
Nope... seems not to work :(
Maybe jester could be extended to export createRoute(body, caseStmtGetBody, i) in a way that the route can get created without being in the context of the routes macro.
'system.slurp' and 'macros.parseStmt' can do the trick although a bit complicated
route1.jes:
routes:
get "/":
resp """ {"status": "ok"} """, "application/json"
route2.jes:
get "/anotherpart":
resp """ {"status": "ok"} """, "application/json"
route.nim:
import jester, asyncdispatch, macros
macro abc(): stmt =
let a = slurp("route1.jes")
let b = slurp("route2.jes")
result = parseStmt(a)
result[0][1].add parseStmt(b)[0] #here things quickly become complicated
abc()