An API Gateway event wrapper for AWS Lambda functions for REST APIs
$ npm install aws-serverless-restful-wrapper
GET /todos/{id}
const restful = require('aws-serverless-restful-wrapper')
module.exports.get = restful.document({
target: async (path, query, headers) => {
console.log('Returning todo')
return {
id: '123',
text: 'My task',
checked: true
}
}
})
HTTP 200
Content-Type: 'application/json'
{
"id": "123",
"text": "My task",
"checked": true
}
const restful = require('aws-serverless-restful-wrapper')
module.exports.get = restful.collection({
target: async (path, query, headers) => {
console.log('Returning todos')
return [
{
id: '1',
text: 'My task 1',
checked: true
},
{
id: '2',
text: 'My task 2',
checked: true
}
]
}
})
HTTP 200
Content-Type: 'application/json'
[
{
"id": "1",
"text": "My task 1",
"checked": true
},
{
"id": "2",
"text": "My task 2",
"checked": true
}
]
const Joi = require('@hapi/joi')
const restful = require('aws-serverless-restful-wrapper')
module.exports.get = restful.document({
validators: {
path: Joi.object({
id: Joi.string().required()
})
},
target: async (path, query, headers) => {
console.log('Returning todo')
return {
text: 'My task',
checked: true
}
}
})
This source code is licensed under the MIT license found in the LICENSE.txt file.