This is the main api class. With this class you can add/manage api routes, manage policies and change the api folders/urls. The api is used to easily obtain data from the server while also respecting things like security by using policies. The response for the api works in a RESTful manner and can be managed using the assigned JSON class object.
This function is used to create a new api route. An api is a way to easily obtain data from you server that you need from your client. Apis can also be used to trigger actions on the server. This can be things like logging users in. For more information about api you can read the tutorial about it. You can set the url of the api with the url parameter. You can also add policies to your api route. Policies are functions that check if the client is allowed to continue on to the api function. You can manage policies using policies using the policy class and there also is a tutorial about policies.
cerus.api().add("test")
.then(function(req, res) {
res.emit();
});
// -> routes the api route to "/api/test"
This function will return the folders class for this module. With this class you can change the folders which are used to store the api classes and policy classes.
With this function you can load an api or policy class. The api classes should contain the functions used for routing api requests. The policy classes should contain the policies. To load the class it will use the general require function. The folders that should contain the classes can be changed using the api.folders function.
With the class this function returns you can manage the policies for the api. The policies are used as middleware before the api function is called. These policies are used for things like security and to check if the client is logged in. You can easily add policies using the api.policy function.
This function is used for a shortcut to add a new policy. You can specify the name with the inserted parameter. This function will return a promise that will be called on the 'policy' event when the policy is used. The api request will be stopped when the policy has emitted a response. The 'policy' event will e called with the request, json response and cerus as parameters.
With this function you can remove an api route. It basically directly removes it from the router.
cerus.api().remove("/");
// -> this removes the "/" api route
This function will return the urls class for this module. This class is used to store the url for the api.