How to make an API adapter

You’re better off if you know the concepts behind building an API adapter of your own rather than using a pre-written one you don’t understand.

These are the questions you should be asking:

  • What is an API adapter? Why is it helpful?

    • Many modern applications have APIs which are expressed as web APIs. An API adapter in the context of Iguana X is a library written in Lua which makes it easier to use the API than if one was writing the code without any structure.

  • How does an API adapter make it easier?

    • It comes down to solving some of the ‘boilerplate’ things one would need to do in order to access an API.

  • What are the ‘low lying’ boilerplate things an adapter can implement to make the API easier to use?

    • Think about these problems:

      • How do I authenticate against the API?

      • How do I know what calls exist for the API?

      • For each call how can I make it easier to remember what parameters the API accepts and then use the data which comes back?

      • If I make a bad call against the API can my adapter handle the error messages that come back?

The answers to all these questions are slightly different for every API since each vendor and application does them slightly differently. But if you ask these questions one by one and methodically answer them then it becomes possible to build good adapters to each API. Which leads to one final question…

Is it better to use an opaque adapter for an API that I don’t understand?

Or, is it better than I understand the core principles of how an adapter is written so that if need it do something different, that I can adapt it to meet my needs?

 

Related pages