admin管理员组

文章数量:1319485

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.

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.

Share Improve this question asked Feb 12, 2012 at 17:15 Claudio DonzelliClaudio Donzelli 511 silver badge2 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

Take a look at Backbone.js http://documentcloud.github./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.

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!');
    }
});

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() :)

本文标签: jsonBest Javascript framework for RESTful HTTP networkingStack Overflow