jsonapi-server
Advanced tools
Comparing version 0.12.2 to 0.13.0
@@ -37,1 +37,3 @@ 2015-06-29 - Initial release | ||
2015-11-11 - v0.12.2 | ||
2015-11-12 - Handlers readiness check | ||
2015-11-12 - v0.13.0 |
### Creating Custom Handlers | ||
Handlers represent the mechanism that backs a resource. Each handler is expected to provide some of the following functions: | ||
* initialise - when jsonapi-server loads, this is invoked once for every resource using this handler. Its an opportunity to allocate memory, connect to databases, etc. | ||
* search - for searching for resources that match some vague parameters. | ||
* find - for finding a specific resource by id. | ||
* create - for creating a new instance of a resource. | ||
* delete - for deleting an existing resource. | ||
* update - for updating an existing resource. | ||
Handlers represent the mechanism that backs a resource. Each handler is expected to provide: | ||
* a `ready` property indicating the handler is ready to process requests. | ||
* some of the following functions: | ||
* `initialise` - when jsonapi-server loads, this is invoked once for every resource using this handler. Its an opportunity to allocate memory, connect to databases, etc. | ||
* `search` - for searching for resources that match some vague parameters. | ||
* `find` - for finding a specific resource by id. | ||
* `create` - for creating a new instance of a resource. | ||
* `delete` - for deleting an existing resource. | ||
* `update` - for updating an existing resource. | ||
Failure to provide the above handler functions will result in `EFORBIDDEN` HTTP errors if the corresponding REST routes are requested. | ||
@@ -67,2 +70,6 @@ | ||
#### ready | ||
The `ready` property should be set to a _truthy_ value once the handler is ready to process requests (which will usually happen at the end of `initialise`). If the handler is temporarily unable to process requests this property should be set to a _falsy_ value during the down period. | ||
#### initialise | ||
@@ -69,0 +76,0 @@ `initialise` is invoked with the `resourceConfig` of each resource using this handler. |
@@ -10,2 +10,7 @@ "use strict"; | ||
/** | ||
Handlers readiness status. This should be set to `true` once all handlers are ready to process requests. | ||
*/ | ||
memoryStore.handlers.ready = false; | ||
/** | ||
initialise gets invoked once for each resource that uses this hander. | ||
@@ -16,2 +21,3 @@ In this instance, we're allocating an array in our in-memory data store. | ||
resources[resourceConfig.resource] = resourceConfig.examples || [ ]; | ||
memoryStore.handlers.ready = true; | ||
}; | ||
@@ -18,0 +24,0 @@ |
@@ -51,2 +51,11 @@ "use strict"; | ||
if (!resourceConfig.handlers.ready) { | ||
return helper.handleError(request, res, { | ||
status: "503", | ||
code: "EUNAVAILABLE", | ||
title: "Resource temporarily unavailable", | ||
detail: "The requested resource '" + request.params.type + "' is temporarily unavailable" | ||
}); | ||
} | ||
if (!resourceConfig.handlers[handlerRequest]) { | ||
@@ -53,0 +62,0 @@ return helper.handleError(request, res, { |
{ | ||
"name": "jsonapi-server", | ||
"version": "0.12.2", | ||
"version": "0.13.0", | ||
"description": "A fully featured NodeJS sever implementation of json:api. You provide the resources, we provide the api.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
58
3580
159697