Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
claudia-api-builder
Advanced tools
#Claudia API Builder
This utility simplifies Node.js Lambda - API Gateway handling.
The API builder is designed to work with Claudia, and add minimal overhead to client projects.
An instance of the Claudia API Builder should be used as the module export from your API module. You can create a new API simply
by instantiating a new ApiBuilder
, then defining HTTP handlers for paths by calling .get
, .put
, and .post
. For example, the following
snippet creates a single handler for a GET
call to /greet
, responding with a parameterised message:
var ApiBuilder = require('claudia-api-builder'),
api = new ApiBuilder(),
superb = require('superb');
module.exports = api;
api.get('/greet', function (request) {
'use strict';
return request.queryString.name + ' is ' + superb();
});
For a more detailed example, see the Web API Example project.
Claudia will automatically bundle all the parameters and pass it to your handler, so you do not have to define request and response models. The request
object passed to your handler contains the following properties:
queryString
: a key-value map of query string argumentsenv
: a key-value map of the API Gateway stage variables (useful for storing resource identifiers and access keys)headers
: a key-value map of all the HTTP headers posted by the clientpost
: in case of a FORM post (application/x-form-www-urlencoded
), a key-value map of the values postedbody
: in case of an application/json
POST or PUT, the body of the request, parsed as a JSON objectYou can either respond synchronously (just return a value, as above), or respond with a Promise
. In that case, the lambda function will wait until the
Promise
resolves or rejects before responding. Please note that AWS currently uses Node.js 0.10.36, which does not include the standard Promise
library,
so you need to include a third party one. API Builder just checks for the .then
method, so it should work with any A+ Promise library.
By default, Claudia.js uses 500 as the HTTP response code for all errors, and 200 for successful operations. The application/json
content type is default for both successes and failures. You can change all that by using the optional third argument to handler definition methods. All keys are optional, and the structure is:
error
: a number of a key-value map. If the number is specified, then that's used as the HTTP response code. If the key-value map is specified, it should have the following keys:
code
: HTTP response codecontentType
: the content type of the responsesuccess
: a number of a key-value map. If the number is specified, then that's used as the HTTP response code. If the key-value map is specified, it should have the following keys:
code
: HTTP response codecontentType
: the content type of the responseThese special rules apply to content types and codes:
To see these options in action, see the Serving HTML Example project .
FAQs
Simplify AWS ApiGateway handling
The npm package claudia-api-builder receives a total of 1,619 weekly downloads. As such, claudia-api-builder popularity was classified as popular.
We found that claudia-api-builder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.