• Latest
Managing Multiple APIs Using an Adapter Pattern

Managing Multiple APIs Using an Adapter Pattern

March 8, 2023
Chris Pratt Defends “The Voices” In The Mario Movie

Chris Pratt Defends “The Voices” In The Mario Movie

March 30, 2023
Data Lakehouses: The Future of Scalable, Agile, and Cost-Effective Data Infrastructure

Data Lakehouses: The Future of Scalable, Agile, and Cost-Effective Data Infrastructure

March 30, 2023
AUDL Moments: Marques Brownlee Championship Game Layout

AUDL Moments: Marques Brownlee Championship Game Layout

March 30, 2023
Optimizing Machine Learning Deployment: Tips and Tricks

Optimizing Machine Learning Deployment: Tips and Tricks

March 30, 2023
AutoCAD and Maya now runs natively on Apple Silicon Macs

AutoCAD and Maya now runs natively on Apple Silicon Macs

March 30, 2023
8 Proven Ways to Combat End-of-Life Software Risks

8 Proven Ways to Combat End-of-Life Software Risks

March 30, 2023

The Best Smartphone Camera 2022!

March 30, 2023
Yes, The Super Mario Bros. Movie Will Have A Post-Credits Scene

Yes, The Super Mario Bros. Movie Will Have A Post-Credits Scene

March 30, 2023
Main sirf Allah ke Aage jhukne wala hon #shorts#aimim

Main sirf Allah ke Aage jhukne wala hon #shorts#aimim

March 30, 2023
Check out BLUETTI’s new AC60 solar generator and B80 battery

Check out BLUETTI’s new AC60 solar generator and B80 battery

March 30, 2023
Horizon Forbidden West Expansion’s Impressive Cloud Tech Is a Big Reason It’s PS5 Only

Horizon Forbidden West Expansion’s Impressive Cloud Tech Is a Big Reason It’s PS5 Only

March 30, 2023
ulama e deoband zindabaad #shorts #ulmaedeoband

ulama e deoband zindabaad #shorts #ulmaedeoband

March 30, 2023
Advertise with us
Thursday, March 30, 2023
Bookmarks
  • Login
  • Register
GetUpdated
  • Game Updates
  • Mobile Gaming
  • Playstation News
  • Xbox News
  • Switch News
  • MMORPG
  • Game News
  • IGN
  • Retro Gaming
  • Tech News
  • Apple Updates
  • Jailbreak News
  • Mobile News
  • Software Development
  • Photography
  • Contact
No Result
View All Result
GetUpdated
No Result
View All Result
GetUpdated
No Result
View All Result
ADVERTISEMENT

Managing Multiple APIs Using an Adapter Pattern

March 8, 2023
in Software Development
Reading Time:4 mins read
0 0
0
Share on FacebookShare on WhatsAppShare on Twitter


Let’s imagine the problem: Your company creates a B2B product that provides a service for some other companies. This service helps client-company to resolve very specific problems of their customers. This customer can communicate with our company web app and do some operations. The results of these operations should be reported to the other company side. 

business relations showcase

Times go on, and now you have a few more clients that work by the same scheme. At first, you connect small companies one by one, but when you get to much bigger client companies, you discover that they use third-party API service providers and delegate all the integration problems to them. These API service providers act as a proxy for this toil of service reverse integration, which unifies the logic of cross-company communication on both sides. Due to the structure of presented business relationships, our company almost inevitably start to use a set of similar actions to communicate with dozens of different APIs for hundreds of clients in the future. 

B2B communication as is

To make things easier, we should unify the communication logic between our services and external APIs.

The main idea is to create a single scalable transaction service and use it to transform some kind of unified DTOs into API-specific information and vice versa.

scalable transaction service

For HTTP, our adapters should be able to:

  • Transform unified request DTO into API-specific request DTO
  • Transform API-specific response DTO and HTTP status code into unified response DTO

To do so, firstly, we need to understand the building blocks of our communication.

HTTP request consists of:

  • HTTP method;
  • URL path;
  • URL params;
  • headers structure;
  • request body (any format: JSON, XML, plain text).

HTTP response consists of:

  • Response headers;
  • Response body (may also contain an error code that must be combined with the HTTP status code and translated into a unified error code format).

All items listed above are illustrated on the next image: 

request & response structure

It’s important to understand which elements of communication may vary between API providers and which are client-specific. For example, in API URL: protocol, domain name, and port are Client specific parts, but the request URL path and URL params are API-specific.

After we know what elements should be unified in our adapters, we need to make sure we always use the right adapter for our request. The easiest way to do so is to use some unique ClientId to identify an API unique keyword from the database. After getting one, we can simply use static Map<API_KEY, ApiAdapter> to pass our data further. 

It is highly recommended for unified request data to have full information about entities. This way, you will never experience a lack of information on the API adapter’s side. For example, if a request into your transaction service contains the ‘ClientId’ field, consider getting full ClientEntity [clientId, apiKey, mainCurrency, URL_protocol, domain, … ] from the database and pass it into your adapter (do it any way you are comfortable with).

Adapter holder

After combining these 2 simple steps, we got the next code structure:

Now, whenever you need to do API reverse integration, you simply need to add new request and response adapters and do all necessary API-specific transformations in one place.



Source link

ShareSendTweet
Previous Post

Topaz Labs Denoise AI: Turning down the noise

Next Post

Elder Scrolls Online’s Return To Morrowind Trailer Dives Deep Into Dev Nostalgia

Related Posts

Data Lakehouses: The Future of Scalable, Agile, and Cost-Effective Data Infrastructure

March 30, 2023
0
0
Data Lakehouses: The Future of Scalable, Agile, and Cost-Effective Data Infrastructure
Software Development

In today's data-driven world, businesses across industries are increasingly dependent on data warehouse and data lake solutions to store, process,...

Read more

Optimizing Machine Learning Deployment: Tips and Tricks

March 30, 2023
0
0
Optimizing Machine Learning Deployment: Tips and Tricks
Software Development

Machine learning has become an integral part of many industries, from healthcare to finance and beyond. It provides us with...

Read more
Next Post
Elder Scrolls Online’s Return To Morrowind Trailer Dives Deep Into Dev Nostalgia

Elder Scrolls Online's Return To Morrowind Trailer Dives Deep Into Dev Nostalgia

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

© 2021 GetUpdated – MW.

  • About
  • Advertise
  • Privacy & Policy
  • Terms & Conditions
  • Contact

No Result
View All Result
  • Game Updates
  • Mobile Gaming
  • Playstation News
  • Xbox News
  • Switch News
  • MMORPG
  • Game News
  • IGN
  • Retro Gaming
  • Tech News
  • Apple Updates
  • Jailbreak News
  • Mobile News
  • Software Development
  • Photography
  • Contact

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?