Cloud Zone is brought to you in partnership with:

CTO of CloudWork. Bruno Pedro is a Web and Cloud Computing Technologist with over fifteen years experience in the field. Bruno is the founder of Tarpipe (acquired by Nubera), a platform to streamline updates to various social websites, creating a range of simple to complex workflows between social media apps. He also founded JobTide (acquired by AdClick), a job search engine and company directory operating in Brazil, Denmark and Portugal. Bruno has been developing Open Source and commercial applications since 1995. He's an O'Reilly author and a regular speaker at industry related events. In his spare time he enjoys exploring the Internet of Things with the Arduino platform. Bruno has posted 1 posts at DZone. You can read more from them at their website. View Full User Profile

Using Facades to Decouple API Integrations

03.13.2013
| 7859 views |
  • submit to reddit

The most important part of building an integration with an API is actually writing the code that will connect with the Web service and invoke its methods. I'll show you why using the Façade pattern to decouple calls from your existing code is a good idea and help you identify what kind of problems you might be able to prevent.


So, first things first, what is the Façade pattern?


A Façade is an object that provides simple access to complex - or external - functionality. It might be used to group together several methods into a single one, to abstract a very complex method into several simple calls or, more generically, to decouple two pieces of code where there's a strong dependency of one over the other.


What happens when you develop API calls inside your code and, suddenly, the API is upgraded and some of its methods or parameters change? You'll have to change your application code to handle those changes. Also, by changing your internal application code, you might have to change the way some of your objects behave. It is easy to overlook every instance and can require you to doublecheck multiple lines of code.

There's a better way to keep API calls up-to-date. By writing a Façade with the single responsibility of interacting with the external Web service, you can defend your code from external changes. Now, whenever the API changes, all you have to do is update your Façade. Your internal application code will remain untouched.




From a Test Driven Development point-of-view, using a Facade offers a big advantage. You're now able to write simple tests against the Façade without affecting your internal code test results. By using this strategy, you'll be able to know immediately whenever an API is not working as you expected and make the necessary changes to the Façade.


This is the approach we follow at CloudWork  when building integrations between any third-party APIs. API Façades act as tight compartments that protect the rest of the application from external changes and simplify the way we interact with different Web services.


This article is cross-posted at Using Facades to Decouple API Integrations.

Published at DZone with permission of its author, Bruno Pedro.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Robert Morschel replied on Wed, 2013/03/20 - 8:53am

 Interesting, because as well as an abstraction, decoupling layer, the facade allows things like throttinling and usage charging to be implemented without affecting the underlying services.  This is the approach being promoted by 3rd party api management product vendors like Apigee, Layer 7, and WS02.  Out of interest, do you have a preference for build vs buy in this area?

Robert

SOA API Management Product Evaluation


John Batista replied on Wed, 2014/02/05 - 12:15am

 

However, the authorized bankruptcy sector has gotten an undesirable rap caused by a few profit-driven legal representatives. However, your regular bankruptcy attorney generally is a pretty very good guy.
bank ruptcy attorney cleveland

John Batista replied on Wed, 2014/02/05 - 12:16am

 

Companies and corporations often work with important risk on account of an around dependency in reactive threat countermeasures along with vulnerability encoding tools.
business cyber security

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.