Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API Wrapper Architecture Best Practice

I'm writing a Perl wrapper module around a REST webservice and I'm hoping to have some advice on how best to architect the module.

I've been looking at a couple of different Perl modules for inspiration.

Flickr::Simple2 is basically one big file with methods wrapping around the different methods in the Flickr API, e.g. getPhotos() etc.

Flickr::API is a sub-class of another module (LWP) for making HTTP requests. So basically it just allows you to make calls through the module, using LWP, that go to the correct API method/URL without defining any wrapper methods itself. That's explained pretty poorly - but basically it has a method that takes an argument (a API method name) and constructs the correct API call, e.g. request()/response().

An alternative design would be like the first described, but less monolithic, with separate classes for separate "areas" of the API.

I'd like to follow modern/best practice Perl methods so I'm using Dist::Zilla to build the module and Moose for the OO stuff but I'd appreciate some input on how to actually design/architect my wrapper.

Guides/tutorials or pointers to other well designed modules would be appreciated.

Cheers

like image 594
Adam Taylor Avatar asked Jun 06 '10 17:06

Adam Taylor


People also ask

What makes a good API wrapper?

Idiomatic consistency Put simply, this means your wrapper should smell like language in which it is written — Ruby like Ruby, Java like Java, PHP like PHP, and so on. This usually comes into play when language conventions bleed through an API in the form of method and variable names.

What is an API wrapper?

An API wrapper provides a way to access an API through a particular programming language or interface, which can help streamline the process of making API calls. Please explore the wrappers linked on the right for more information.

Which of the following is a best practice for designing an API?

Conclusion. The most important takeaways for designing high-quality REST APIs is to have consistency by following web standards and conventions. JSON, SSL/TLS, and HTTP status codes are all standard building blocks of the modern web. Performance is also an important consideration.


1 Answers

Joshua Bloch has good tips on "How to Design a Good API and Why it Matters" (video, 2007).

The slides (PDF).

like image 197
dolmen Avatar answered Sep 28 '22 05:09

dolmen