Skip to content

dnyanesh-genpact/API-Gateway-Design-Pattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

API-Gateway-Design-Pattern

The API Gateway Design Pattern of Microservices Architecture

Problem that API Gateway Design Pattern solves

Microservices architectures often involve multiple services that clients need to interact with. Directly managing these individual service endpoints can be complex for clients.

Solution for this problem

API Gateways aggregate multiple microservices into a single entry point, simplifying client interactions by providing a unified API.

Prerequisites

  • Java Development Kit (JDK 8 or above)
  • Maven
  • IDE like STS(Spring Tool Suite) or Eclipse

Architecture Overview

We will create 3 microservices :

  • Account Service -> Manages Bank Account creation and fetching
  • Fund Transfer Service -> Manages trasnfer of funds for accounts
  • Banking Gateway Service -> This will be our API Gateway Service that will have both Account and Fund Transfer services registered with it.

Steps :

  1. Create Microservices : Create three separate Spring Boot projects (either via Spring Initializr or your preferred method).

  2. Add Dependencies : For API Gateway Service, add following dependencies : image

    For Account and Fund Transfer service, add following dependencies : image

  3. Business Logic :

    1. Account Service - Create a REST API to get an account by account number.
    2. Fund Transfer Service - Create a REST API to get transaction details for specific account.
    3. Banking Gateway Service(API Gateway Service) - Create a basic API Gateway Service that will call above 2 services upon getting client request.
  4. API Gateway Configuration : Configure the API Gateway service with URI and Header based routing for Account and Fund Transfer Service respectively.

  5. Run the services : Start all 3 services i.e. Account Service, Fund Transfer Service and API Gateway Service.

  6. Test and connect h2 DB connection : Connect to Account Service DB using jdbc:h2:mem:AccountService_DB on h2 console. Connect to Account Service DB using jdbc:h2:mem:FundTransfer_DB on h2 console.

  7. For testing Gateway, make a few calls on both Account and Fund Transfer Services using following URLs that use port 8080(Default API Gateway port):

    Account Service POST call - http://localhost:8080/banking/account/createAccount

    Fund Transfer Service POST call - http://localhost:8080/banking/fundTransfer/newFundTransferRequest

    Account Service GET call - http://localhost:8080/banking/account/getBankAccounts

    Fund Transfer Service GET call - http://localhost:8080/banking/fundTransfer/getTransactions

    Make sure to make use of Header along with Body while making a POST call on Banking Gateway Service.

Microservices Configuration

Customize the behavior of services by editing the respective application.properties file. Adjust settings such as port, logging, and error handling.

image

image

image

Sample Code for Controllers and Models

Account Controller :

image

Account Model :

image

FundTransfer Controller :

image

FundTransfer model :

image

Contributing

Contributions are welcome!

Contact

For questions or feedback, please email at tathoded@gmail.com OR dnyaneshsunilrao.tathode@genpact.com.

About

The API Gateway Design Pattern of Microservices Architecture

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages