Coder Social home page Coder Social logo

api-gateway-example's Introduction

NGINX API Gateway

This repo is an example of how to create an NGINX proxy as a gateway to your micro services.

There's a detailed blog post about it.

The important thing is that you can run tests to verify that the gateway routing is done correctly, meaning a request is routed to a specified service with a specified path.

For example, you can verify that an HTTP call to http://api.mycompany.com/login is routed to your authentication service with the /login path.

Running The Test

Make sure docker and docker-compose are installed on your machine.

Clone this repository:

$ git clone [email protected]:nanit/api-gateway-example.git

And run the tests:

$ cd api-gateway-example && make test

All tests should pass which means that:

  1. A request to http://your.gateway.com/login is routed to the authentication service with the /login path
  2. A request to http://your.gateway.com/messages is routed to the inbox service with the /messages path

Project Structure

  1. spec/app/spec/expected_routes.yml - the route specs. Each route has an expected destination service name and an expected destination path.

  2. app/services/<service_name>.conf - per-service routes configuration.

  3. app/nginx.conf - the main nginx configuration file.

  4. docker-compose.yml - add new services here.

You should only change these 4 to fit your specific needs. The rest of the files may remain untouched.

Adding a New Route

  1. Add the route to spec/app/spec/expected_routes.yml

  2. Run make test in the root directory and see the tests fail.

  3. Add the proper NGINX configuration.

  4. Run make test again in the root directory and (hopefully) see the tests pass.

Adding a New Micro Service

  1. Add the service to docker-compose.yml. Make sure the SERVICE_NAME environment variable is set properly, and that the gateway is linked to it.

  2. Add your service specs to spec/app/spec/expected_routes.yml

  3. Run make test in the root directory to see the specs fail.

  4. Add app/services/new_service.conf with the proper routing to your new service.

  5. Run make test in the root directory again and (hopefully again) see the tests pass.

api-gateway-example's People

Contributors

erez-rabih 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.