5

I am more of a backend guy, but frontend development really intrigues me as I make my first steps in seeing the browser as the environment for rich and awesome applications.

What is the most suitable Javascript framework for working with a RESTful HTTP API, in other words, for retrieving (HTTP GET) and submitting (HTTP POST/PUT/DELETE) JSON representations of resources?

I am looking for a framework (if it exists!) that provides good abstraction and encapsulation of HTTP request/response, handles cross-domain and cross-browser issues.

3 Answers 3

3

Take a look at Backbone.js http://documentcloud.github.com/backbone/

Its lightweight, does not have many dependencies (only Underscore.js) and its real easy to use, yet pretty flexible and powerful.

From the site;

Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.

2

You can use jQuery with its .ajax() function. Example:

$.ajax({
    url: '/users',
    type: 'PUT',
    data: { name: 'John Doe', age: 30 },
    success: function ( data ) {
        alert('John Doe inserted!');
    }
});
0

You can use fetch, it's a lightweight framework that does only fetching (or unirest.io)

fetch('/users.json')
  .then(function(response) {
    return response.json()
  }).then(function(json) {
    console.log('parsed json', json)
  }).catch(function(ex) {
    console.log('parsing failed', ex)
  })

And please don't use jQuery just for .ajax() :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.