server
- Description:
- HTTP server functionality using Express.js
- Source:
Classes
- Router
- ServerModule
- ServerUtils
Methods
(static) exports.addExistenceProps(req, res, next)
- Description:
- Adds extra properties to the request object to allow for easy existence checking of common request objects
- Source:
Example
"IMPORTANT NOTE: body data is completely ignored for GET requests, any code
requiring it should switch to use POST."
let req = { 'params': { 'foo':'bar' }, 'query': {}, 'body': {} };
req.hasParams // true
req.hasQuery // false
req.hasBody // false
Parameters:
| Name |
Type |
Description |
req |
external:ExpressRequest
|
|
res |
external:ExpressResponse
|
|
next |
function
|
|
(static) exports.cacheRouteConfig(routeConfig) → {function}
- Description:
- Caches the route config on the incoming request
- Source:
Parameters:
| Name |
Type |
Description |
routeConfig |
Route
|
|
Returns:
-
Type
-
function
(static) exports.generateRouterMap(topRouter) → {Object}
- Description:
- Generates a map for a given router
- Source:
Parameters:
| Name |
Type |
Description |
topRouter |
Router
|
|
Returns:
The route map
-
Type
-
Object
(static) exports.getAllRoutes(router) → {Map.<string, Set.<string>>}
- Description:
- Collects all registered routes with their methods across the router hierarchy
- Source:
Parameters:
| Name |
Type |
Description |
router |
Router
|
The router to traverse |
Returns:
Map of route paths to sets of allowed methods
-
Type
-
Map.<string, Set.<string>>
(static) exports.mapHandler(topRouter) → {function}
- Description:
- Handler for returning an API map
- Source:
Parameters:
| Name |
Type |
Description |
topRouter |
Router
|
|
Returns:
Middleware function
-
Type
-
function
Type Definitions
Route
- Description:
- Defines how an individual API route should be handled
- Source:
Properties:
| Name |
Type |
Description |
route |
String
|
The name of the api (this will be used as the API endpoint) |
handlers |
Object
|
Object mapping HTTP methods to request handler functions. Note: Any HTTP methods not specified in `handlers` will not be exposed.
Properties
| Name |
Type |
Attributes |
Description |
post |
Array.<function()>
|
function
|
<optional>
|
POST handlers for the route |
get |
Array.<function()>
|
function
|
<optional>
|
GET handlers for the route |
put |
Array.<function()>
|
function
|
<optional>
|
PUT handlers for the route |
delete |
Array.<function()>
|
function
|
<optional>
|
DELETE handlers for the route |
|
Defines how an individual API route should be handled
Type:
Example
{
route: '/:id?',
handlers: {
// can be an array of middleware/handlers
post: [beforePost, handlePostRequest, afterPost],
// or an individual function
get: getRequest,
put: putRequest,
// or an in-line function
delete: (req, res, next) => { next(); }
}
}