Skip to content

An API Gateway event wrapper for AWS Lambda functions for REST APIs

License

Notifications You must be signed in to change notification settings

diegotremper/aws-serverless-restful-wrapper

aws-serverless-restful-wrapper


NOTE This package is no longer maintained and was moved to @cloudifyjs/restful.

An API Gateway event wrapper for AWS Lambda functions for REST APIs

CircleCI npm npm codecov dependencies Status devDependencies Status Known Vulnerabilities Greenkeeper badge

Install

$ npm install aws-serverless-restful-wrapper

Features

Usage

Fetch a single document

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
    }
  }
})

API Gateway Response:

HTTP 200
Content-Type: 'application/json'

{
  "id": "123",
  "text": "My task",
  "checked": true
}

Fetch a collection

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
      }
    ]
  }
})

API Gateway Response:

HTTP 200
Content-Type: 'application/json'

[
  {
    "id": "1",
    "text": "My task 1",
    "checked": true
  },
  {
    "id": "2",
    "text": "My task 2",
    "checked": true
  }
]

Using Joi validation

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
    }
  }
})

Contributing

  • Write docs
  • Suggest a feature
  • Submit PRs
    • Logging
    • Support for XML based REST
  • Write exemples

License

This source code is licensed under the MIT license found in the LICENSE.txt file.

About

An API Gateway event wrapper for AWS Lambda functions for REST APIs

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •