claudia-api-builder
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "claudia-api-builder", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Simplify AWS ApiGateway handling", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
#Claudia API Builder | ||
This utility simplifies Node.js Lambda - API Gateway handling. | ||
* can process multiple AWS API Gateway calls from a single Lambda function in Node.js, so that | ||
<img src="https://claudiajs.github.io/claudiajs.com/assets/claudiajs.svg" height="150" align="right" /> | ||
This utility simplifies Node.js Lambda - API Gateway handling. It helps you: | ||
* process multiple AWS API Gateway calls from a single Lambda function in Node.js, so that | ||
you can develop and deploy an entire API simpler and avoid inconsistencies. | ||
* can work with synchronous responses or promises, so you can develop easier | ||
* any exceptions or promise rejections are automatically reported to Lambda as errors | ||
* any synchronous responses or promise resolutions are automatically reported to Lambda as results | ||
* work with synchronous responses or promises, so you can develop easier | ||
* handle exceptions or promise rejections automatically as Lambda errors | ||
* handle synchronous responses or promise resolutions automatically as Lambda | ||
* configure response content types and HTTP codes easily | ||
The API builder is designed to work with [Claudia](https://github.com/claudiajs), and add minimal overhead to client projects. | ||
[![Join the chat at https://gitter.im/claudiajs/claudia](https://badges.gitter.im/claudiajs/claudia.svg)](https://gitter.im/claudiajs/claudia?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
## API definition syntax | ||
@@ -26,3 +32,2 @@ | ||
api.get('/greet', function (request) { | ||
'use strict'; | ||
return request.queryString.name + ' is ' + superb(); | ||
@@ -54,6 +59,6 @@ }); | ||
* `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: | ||
* `error`: a number or a key-value map. If a number is specified, it will be used as the HTTP response code. If a key-value map is specified, it should have the following keys: | ||
* `code`: HTTP response code | ||
* `contentType`: the content type of the response | ||
* `success`: 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: | ||
* `success`: a number or a key-value map. If a number is specified, it will be used as the HTTP response code. If a key-value map is specified, it should have the following keys: | ||
* `code`: HTTP response code | ||
@@ -64,8 +69,8 @@ * `contentType`: the content type of the response | ||
* When the error content type is text/plain, only the error message is sent back in the body, not the entire error structure. | ||
* When the error content type is application/json, the entire error structure is sent back . | ||
* When the response type is application/json, the response is JSON-encoded. So if you just send back a string, it will have quotes around it. | ||
* When the response type is text/plain, text/xml, text/html or application/xml, the response is sent back without JSON encoding (so no extra quotes). | ||
* In case of 3xx response codes for success, Claudia puts the response body into the Location header, so you can easily create HTTP redirects. | ||
* When the error content type is `text/plain` or `text/html`, only the error message is sent back in the body, not the entire error structure. | ||
* When the error content type is `application/json`, the entire error structure is sent back with the response. | ||
* When the response type is `application/json`, the response is JSON-encoded. So if you just send back a string, it will have quotes around it. | ||
* When the response type is `text/plain`, `text/xml`, `text/html` or `application/xml`, the response is sent back without JSON encoding (so no extra quotes). | ||
* In case of 3xx response codes for success, the response goes into the `Location` header, so you can easily create HTTP redirects. | ||
To see these options in action, see the [Serving HTML Example project](https://github.com/claudiajs/example-projects/tree/master/web-serving-html) . | ||
To see these options in action, see the [Serving HTML Example project](https://github.com/claudiajs/example-projects/tree/master/web-serving-html). |
@@ -7,3 +7,3 @@ /*global module */ | ||
routes = {}; | ||
['GET', 'POST', 'PUT'].forEach(function (method) { | ||
['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'PATCH'].forEach(function (method) { | ||
self[method.toLowerCase()] = function (route, handler, options) { | ||
@@ -10,0 +10,0 @@ var pathPart = route.replace(/^\//, ''), |
7503
74