serve .port:18966 [
GET "/" [ "This is the homepage" ]
GET "/post" $[id][
send.html ~"This is the post with id: |id|"
]
POST "/getinfo" $[id][
send.json write.json ø #[
i: id
msg: "This is some info"
]
]
]
; run the app and go to localhost:18966 - that was it!
; the app will respond to GET requests to "/" or "/post?id=..."
; and also POST requests to "/getinfo" with an 'id' parameter
copy
serve $[req][
inspect req
;[ :dictionary
; method : GET :string
; path : / :string
; uri : / :string
; body : :string
; query : [ :dictionary
; ]
; headers : [ :dictionary
; ...
; ]
; we have to return either a string
; or a dictionary like:
#[
body: "..."
status: 200
headers: #[
;...
]
]
]