Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are good examples of REST API client libraries in JavaScript [closed]

Tags:

I'm looking for best-practise styles for wrapping a REST API in a light-weight JavaScript client.

In the past I've seen libraries which are implemented in a style like:

var request = new SearchRequest(apikey);
request.query = "search term";
request.send(function(results) {
    console.log(results);
});

Or that embrace HTTP more explicitly like:

api.get("search", "search term", function(results) {
    console.log(results);
});
api.post("comment", comment, function(results) {
    console.log(results);
});

Or that wrap at an even higher level:

api.search("search term", function(results) {
    console.log(results);
});
api.createComment(comment, function(results) {
    console.log(results);
});

What good examples of modern JavaScript client libraries wrapping REST APIs have you seen recently. Not worried about implementation details, just the API design.

Thanks!

like image 413
Andy Hume Avatar asked Nov 01 '12 10:11

Andy Hume


People also ask

What is REST client library?

Go Up to DataSnap REST. The Embarcadero REST Library is a framework for accessing REST-based web services (REST stands for Representational State Transfer). The library is available for all platforms that are supported by Delphi. The framework focuses on JSON as the representation format.

What is REST API example?

For example, a REST API would use a GET request to retrieve a record, a POST request to create one, a PUT request to update a record, and a DELETE request to delete one. All HTTP methods can be used in API calls. A well-designed REST API is similar to a website running in a web browser with built-in HTTP functionality.

What is REST API in JavaScript?

A REST API is a way of easily accessing web services. When a RESTful API is called, the server will transfer to the client a representation of the state of the requested resource.


1 Answers

I watched a really good video on good API Design. Definitely worth the watch.

RESTful API Design - Second Edition

You can also get a free book Web API Design - Crafting Interfaces that Developers Love in addition to the above video by going to http://bit.ly/M28lOu

Regarding wrappers it may be worth thinking about the following:

  1. Make your wrapper consistent.

Adopt the standards, naming conventions, etc of the programming language or community you are working with to make the wrapper feel as natural as possible to those using it.

  1. To wrap or to abstract? That is the question.

By Wrapping you mimic the REST API methods and structure as much as possible but simply make some of the hard things easier. One of the biggest advantages of this approach is that it makes it easier to upgrade when the target REST API upgrades.

Abstracting is useful when the target REST API is complex or behaves and looks in non-standard ways. In this case your wrapper methods and calls may not resemble your target REST API methods at all but will ultimately simplify the life ( hopefully ) of those using your wrapper.

like image 56
Bruno Avatar answered Sep 28 '22 06:09

Bruno