Coder Social home page Coder Social logo

api-gateway-design-pattern's Introduction

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 [email protected] OR [email protected].

api-gateway-design-pattern's People

Contributors

dnyanesh-genpact avatar

Watchers

 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.