DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Commonly Occurring Errors in Microsoft Graph Integrations and How To Troubleshoot Them (Part 7)
  • Mocking and Its Importance in Integration and E2E Testing
  • API Logic and Workflow Integration
  • Securely Sign and Manage Documents Digitally With DocuSign and Ballerina

Trending

  • DZone's Article Submission Guidelines
  • The End of “Good Enough Agile”
  • MCP Servers: The Technical Debt That Is Coming
  • GitHub Copilot's New AI Coding Agent Saves Developers Time – And Requires Their Oversight
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Managing Multiple APIs Using an Adapter Pattern

Managing Multiple APIs Using an Adapter Pattern

Short guide on how to optimise HTTP API integrations in B2B business.

By 
Mykyta Khomenko user avatar
Mykyta Khomenko
·
Mar. 07, 23 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
3.3K Views

Join the DZone community and get the full member experience.

Join For Free

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.

API Adapter pattern Integration

Opinions expressed by DZone contributors are their own.

Related

  • Commonly Occurring Errors in Microsoft Graph Integrations and How To Troubleshoot Them (Part 7)
  • Mocking and Its Importance in Integration and E2E Testing
  • API Logic and Workflow Integration
  • Securely Sign and Manage Documents Digitally With DocuSign and Ballerina

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!