0.1.4 • Published 4 years ago

aws-http-api-gateway v0.1.4

Weekly downloads
6
License
ISC
Repository
github
Last release
4 years ago

AWS HTTP API Gateway Framework

npm version Build Status Coverage Status

AWS API Gateway - HTTP API Framework -- Also called API Gateway v2.

A framework to easily implement HTTP APIs in AWS API Gateway. Implement CRUD operations in less than 100 lines of code!

Test a working demo for your own with this repo.

Docs

The framework complete docs can be found here.

Quick start

  1. Install via npm
npm i aws-http-api-gateway
  1. Setup your serverless function
# serverless.yml
service:
  name: PetStore
provider:
  name: aws
  runtime: nodejs12.x
functions:
  PetsGetManyApi:
    handler: src/apis/pets/get-many.handler
    events:
      - httpApi: 'GET /pets'
  1. Code your handler
// src/apis/pets/get-many.js
'use strict';

const { GetManyApi, ApiHandler } = require('aws-http-api-gateway');

const PetConnector = require('../../connectors/pets');

const petConnector = new PetConnector();

class PetGetManyApi extends GetManyApi {

	get dataConnector() {
		return petConnector;
	}

};

module.exports.handler = ApiHandler(PetGetManyApi);
  1. Code your data connector (implement with your favorite database)
'use strict';

const dbHandler = require('some-db-handler');

module.exports = class PetsConnector {

	get(getParams) {
		return dbHandler.get(getParams);
	}

};
  1. You're ready to go. Just deploy your service!
serverless deploy