Is there a JavaScript library which allow me to perform all the REST operation like (GET
, POST
, PUT
and DELETE
over HTTP
or HTTPS
)?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to fix IE ClearType + jQuery opacity problem i
- void before promise syntax
- jQuery add and remove delay
You can use this jQuery plugin I just made :) https://github.com/jpillora/jquery.rest/
Supports basic CRUD operations, nested resources, basic auth
If you find bugs or want new features, post them in the repositories 'Issues' page please
You can use http://adodson.com/hello.js/ which has
For reference I want to add about ExtJS, as explained in Manual: RESTful Web Services. In short, use method to specify GET, POST, PUT, DELETE. Example:
If the Accept header is necessary, it can be set as a default for all requests:
While you may wish to use a library, such as the excellent jQuery, you don't have to: all modern browsers support HTTP very well in their JavaScript implementations via the XMLHttpRequest API, which, despite its name, is not limited to XML representations.
Here's an example of making a synchronous HTTP PUT request in JavaScript:
This example is synchronous because that makes it a little easier, but it's quite easy to make asynchronous requests using this API as well.
There are thousands of pages and articles on the web about learning XmlHttpRequest — they usually use the term AJAX – unfortunately I can't recommend a specific one. You may find this reference handy though.
Dojo does, e.g. via JsonRestStore, see http://www.sitepen.com/blog/2008/06/13/restful-json-dojo-data/ .
You can also use mvc frameworks like Backbone.js that will provide a javascript model of the data. Changes to the model will be translated into REST calls.