The following methods are supported based on the class context. For further information please refer to the JSDoc generated documentation which includes method arguments
/return
types and general usage examples.
The class methods below should always be declared within the main Lambda function scope.
Method | Description |
---|---|
setPrefix(path) |
Set URI path prefix. |
use(func) |
Load the Route (e.g. Middleware) handler. |
get(path, func) |
Handle HTTP GET requests. |
put(path, func) |
Handle HTTP PUT requests. |
patch(path, func) |
Handle HTTP PATCH requests. |
post(path, func) |
Handle HTTP POST requests. |
delete(path, func) |
Handle HTTP DELETE requests. |
default(func) |
Set router fallback (default route). |
response() |
Return the AWS response object. |
'use strict';
// Load module.
const Router = require('lambda-lambda-lambda');
/**
* @see AWS::Serverless::Function
*/
exports.handler = (event, context, callback) => {
const {request, response} = event.Records[0].cf;
const router = new Router(request, response);
router.methodName();
..
The class methods below are accessible within the Route, Resource, or Middleware handler function scope as req
argument.
Request Method | Description |
---|---|
is(mimeType) |
Check Accept matches the given value. |
header(name) |
Return value for given HTTP header name. |
getHeaders() |
Return the headers of the request. |
method() |
Return the HTTP method of the request. |
uri() |
Return the relative path of the requested object. |
clientIp() |
Return the HTTP client IP (remote address). |
param(name) |
Return the HTTP request parameters or name/value. |
queryString() |
Return the serialized query parameters. |
body() |
Return the base64-encoded body data. |
plugin(name, value) |
Set/Get value passed down the application stack. |
function (req, res, next) {
req.methodName();
..
The class methods below are accessible within the Route, Resource, or Middleware handler function scope as res
argument.
Response Method | Description |
---|---|
setHeader(name, value) |
Set HTTP response header. |
status(code).send(body) |
Send the HTTP response (Array , Buffer , Object , String ). |
status(code).data(buffer) |
Send binary data with HTTP response. |
status(code).json(obj) |
Send the HTTP response as JSON. |
status(code).text(str) |
Send the HTTP response as text. |
function (req, res, next) {
res.methodName();
..