-
Notifications
You must be signed in to change notification settings - Fork 4
Server
The main entry point of FRHTTP is the server object. You can create one as follows:
var server = require('frhttp').createServer();The server object allows users to configure routes and to listen on a port (if desired).
The server object exposes a set of constants, you can read more about them on the Constants page
The server object exposes methods to add handlers for each HTTP method or verb in REST parlance. The parameters for each method are the same, namely a string describing the path.
server.GET(/*string:path*/)
server.HEAD(/*string:path*/)
server.PUT(/*string:path*/)
server.POST(/*string:path*/)
server.DELETE(/*string:path*/)
server.OPTIONS(/*string:path*/)One pseudo-verb is available for use with websockets or other non-http endpoints
server.NON_REST(/*string*/)Each of these methods returns a stream (you can think of this as a sort of promise). When a handler for the path is available the stream will call the function you pass to the onValue method like so:
server.GET(/*a path*/).onValue(function (route) {});For details on variables and wildcards in paths, you can read the paths entry. You can read more about the object sent to the callback in the route object entry.
The server object has a listen method to run in standalone mode:
server.listen(/*int:port*/)The final methods on the server object are available to execute routes manually.
server.runRoute(req, res)
server.runRouteWithRenderer(yourCustomResponder, method, path, injected, params, fn)Most of the time, if you're integrating with a Connect style framework (like Express), you'll be using runRoute.
You may use runRouteWithRenderer for things like websockets or other non-traditional targets. In this case you can provide a custom render method (or null to suppress rendering), a method (GET, HEAD, etc), a path to execute, an object of keys to inject (see the inject section for details), and an alternative render parameter list and function.
Docs
Tutorials