GithubHelp home page GithubHelp logo

wenderjean / apex-api-gateway Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yorunohikage/apex-api-gateway

0.0 2.0 0.0 6 KB

Create and deploy your Apex project on AWS API Gateway using Swagger configuration

License: MIT License

JavaScript 100.00%

apex-api-gateway's Introduction

Apex API Gateway

apex-api-gateway helps you deploying your Apex project into API Gateway. This is an early version, only basic commands are available. If you need more advanced features, you can use AWS CLI.

npm version

This project was inspired by serverless-ci-example's Python deploy script.

Installation

npm install -g apex-api-gateway

Usage

Usage: apex-api-gateway <command> [options]

Commands:
  create <name> [description] [cloneFrom]  Create a new REST API on AWS API Gateway
  update                                   Update the REST API with the new Swagger definitions

Options:
  -c, --config  Apex project JSON file location
  --help        Display help [boolean]

To create an API and update Apex's configuration automatically, just simply do :

apex-api-gateway create 'My Awesome API'

Define swagger file in every function.json you have and main project.json (this should be done automatically later). You can check out the Apex API Gateway Boilerplate.

And to update API :

apex-api-gateway update

Writing your swagger definitions

project.json

After initiating your Apex project, you'll get a project.json containing everything Apex needs to run your lambas. We can then use it to define other definitions under a x-api-gateway key, and here's what you can define.

  • base_path
  • stage_name
  • rest-api-id: You can define this key yourself or let the create command do it for you

paths

You can use this key to match your functions's path and add default Swagger definition. For example, adding CORS to API Gateway can be done like this:

"paths": {
  ".+": { // this will match every path
    "options": { // adding options for preflight requests
      /*
        You can add CORS definitions for OPTIONS request here.
        Check out config example: http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html#enable-cors-for-resource-using-swagger-importer-tool
      */
    }
  },
  "/sweets(.+)": { // match a /sweets path and all the descendants
    "get": { /* ... */ },
    "put": { /* ... */ }
  }
}

Warning: ^ is prepended and $ is appended to the regex matching because I find it easier to match a plain path just writing it. This is questionable and if you disagree, you can open an issue to argue. :P

swagger-func-template

This template represents the default swagger definition for every function defined in your Apex project. The property's behavior is very similar to paths property and will likely be integrated into it in the future. The only difference is this definition is method agnostic.

Example:

"swagger-func-template": {
  "consumes": ["application/json"],
  "produces": ["application/json"],
  "responses": { /* ... */ },
  "x-amazon-apigateway-integration": { /* ... */ },
  "x-amazon-apigateway-auth" : { /* ... */ }
}

myFunction/function.json

This one is easier to define, just define your method in a x-api-gateway key like this:

"x-api-gateway": {
  "method": "post",
  "path": "/sweets",
  "parameters":[/* ... */]
  /* ... */
}

method and paths are required since it will be used as a key for the Swagger main file. The rest is only regular Swagger definition.

apex-api-gateway's People

Contributors

wenderjean avatar yorunohikage avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.