serve

start web server using given routes


Parameters

serve routes :function :block

Attributes

port :integer use given port. Default: 18966
silent don't print info log
chrome open in Chrome windows as an app

Returns

  • :nothing

Examples

copy
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: #[ ;... ] ] ]

Related