Node.js Course
Node.js
/
Advanced

API Gateway

Definition

An API management tool that sits between a client and a collection of backend services. It acts as a reverse proxy to accept all API calls, aggregate the various services required to fulfill them, and return the appropriate result.

Explain Like I'm New

The front desk receptionist at a massive hotel. If the hotel has 50 different departments (Microservices), you don't want the customer (React App) wandering the halls trying to find the Kitchen server, the Billing server, and the Cleaning server. The customer talks ONLY to the Receptionist (API Gateway). The Receptionist figures out exactly which department to call, gathers the info, and hands it to the customer.

Real World Example

AWS API Gateway or Kong. The mobile app only knows one URL: `api.mycompany.com`. When it requests `/users`, the Gateway secretly routes it to Microservice A (Internal IP 10.0.0.1). When it requests `/products`, the Gateway routes it to Microservice B (Internal IP 10.0.0.2).

Common Use Cases

  • •Microservice routing
  • •Centralized Authentication (Gateway checks JWT before letting it into the internal network)
  • •Rate Limiting

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • Does the frontend application need to know the IP addresses of all the underlying microservices?

intermediate

  • Why is Centralized Authentication a major benefit of an API Gateway?

Flash Cards

Question

Frontend need IPs?

Click to reveal answer
Answer

No. The frontend only communicates with the single URL of the API Gateway.

Question

Centralized Auth benefit?

Click to reveal answer
Answer

If you have 20 Microservices, you don't want to write JWT verification code 20 different times. You put the Auth check directly on the API Gateway. If the token is invalid, the Gateway rejects it. If it's valid, it passes the request to the internal microservices, which can now safely assume the user is legitimate.