Best Javascript Structure for RESTful HTTP Network

I'm more like a backend, but the development of the interface really intrigues me when I take the first steps to see the browser as an environment for rich and amazing applications.

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

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

+4
source share
3 answers

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

Its light weight, does not have many dependencies (only Underscore.js) and its real easy to use, but quite flexible and powerful.

From the site;

Backbone.js provides a framework for web applications by providing key-bound models with custom events, collections with a rich API of enumerated functions, views with declarative event handling, and connects them all to an existing API via a RESTful JSON interface.

+3
source

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

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

You can use fetch , this is a lightweight structure that only fetch (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 only for .ajax() :)

0
source

Source: https://habr.com/ru/post/1396051/


All Articles