This project demonstrates how to use NodeJS to build a simple API gateway. In this project I learned how to setup unified authentication and authorization, as well as how rate limiting works.
NOTE: This project does not include any persistence layer (database); it only provides an idea of how the API gateway is configured. You can extend this project based on your preferences.
- NodeJS
- TypeScript
- ExpressJS
PORT=8700 -- This port is for the API Gateway-
Clone the repository
This repository includes two branches: One is the
masterbranch, and the other is thelogin-servicebranch. These two branches represent two different servers, hence you need to clone them separately.- To clone the
masterbranch inside of theapi-gatewayfolder:
git clone --branch master https://github.com/adriandotdev/node-ts-api-gateway.git api-gateway
- To clone the
login-servicebranch inside of thelogin-servicefolder:
git clone --branch login-service https://github.com/adriandotdev/node-ts-api-gateway.git login-service
- To clone the
-
Install dependencies for each application
-
To install all of the dependencies in the
api-gatewayfolder:cd /api-gatewaynpm install
-
To install all of the dependencies in the
login-servicefolder:cd /login-servicenpm install
-
-
Create a
.envfile and provide the required variables listed above.Your
.envfile should look like this:PORT=8700 -
Start the two applications.
-
To start the
api-gatewayapplication:cd /api-gatewaynpm run dev
-
To start the
login-serviceapplication:cd /login-servicenpm run dev
-
-
That's it! You should see the two applications running.
To request via API gateway to all of your APIs, you need to know what are the paths specified in your routes.
Example is inside of your AuthenticationRoutes.ts file you can request to:
http://localhost:8700/api/auth/loginhttp://localhost:8700/api/auth/register
Just look on the path property.