Update README.md
1 file changed
tree: 16a4c3ce867fc1beac3a9626f73370510edf58ab
  1. api-gateway-config/
  2. .gitignore
  3. docker-compose.yml
  4. Dockerfile
  5. init.sh
  6. LICENSE
  7. Makefile
  8. README.md
README.md

apigateway

A performant API Gateway based on Openresty and NGINX.

Table of Contents

Quick Start

docker run -p 80:80 -p 9000:9000 \
            -e REDIS_HOST=<redis_host> \
            -e REDIS_PORT=<redis_port> \
            -e REDIS_PASS=<redis_pass> \
            apicgw/apigateway:latest

This command starts an API Gateway that subscribes to the Redis instance with the specified host and port. The REDIS_PASS variable is optional and is required only when redis needs authentication.

On startup, the API Gateway looks for pre-existing routes in redis, whose keys are defined as routes:<namespace>:<route>, and creates nginx conf files associated with those routes. Then, it listens for any route key changes in redis and updates nginx conf files appropriately. These conf files are stored in the running docker container at /etc/api-gateway/managed_confs/<namespace>/<route>.conf.

API

The following endpoints are exposed to port 9000.

Routes

PUT /routes/{namespace}/{url-encoded-route}

Create/update and expose a new route on the gateway associated with a namespace and a url-encoded route, with the implementation matching the passed values.

body:

{
  "gatewayMethod": *(string) The method that you would like your newly exposed API to listen on.
  "backendURL": *(string) The fully qualified URL that you would like your invoke operation to target.
  "backendMethod": (string) The method that you would like the invoke operation to use. If none is supplied, the gatewayMethod will be used.
  "policies": *(array) A list of policy objects that will be applied during the execution of your route.
  "security": (object) An optional json object defining security policies (e.g. {"type": "apikey"} )
}

Returns:

{
  "managedUrl": (string) The URL at which you can invoke your newly created route.
}

GET /routes/{namespace}/{url-encoded-route}

Get the specified route and return the managed url.

Returns:

{
  "managedUrl": (string) The URL at which you can invoke the route.
}

DELETE /routes/{namespace}/{url-encoded-route}

Delete the specified route from redis and delete the corresponding conf file.

Returns:

Route deleted.

GET /subscribe

This is called automatically on gateway startup. It subscribes to route key changes in redis and creates/updates the necessary nginx conf files.

Subscriptions

PUT /subscriptions/{namespace}/{url-encoded-route}/{api-key}

Add/update an api key for a given route. Alternatively, call PUT /subscriptions/{namespace}/{api-key} to create an api key for the namespace.

Returns:

Subscription created.

DELETE /subscriptions/{namespace}/{url-encoded-route}/{api-key}

Delete an api key associated with the route. Alternatively, call DELETE /subscriptions/{namespace}/{api-key} to delete an api key associated with the namespace.

Returns:

Subscription deleted.

Developer Guide

To build the docker image locally use:

 make docker

To Run the Docker image

 make docker-run-mgmt REDIS_HOST=<redis_host> REDIS_PORT=<redis_port> REDIS_PASS=<redis_pass>

The main API Gateway process is exposed to port 80. To test that the Gateway works see its health-check:

 $ curl http://<docker_host_ip>/health-check
   API-Platform is running!