You don't really need a specific client, it's fairly simple with most libraries. For example in jQuery you can just call the generic $.ajax function with the type of request you want to make:
虽然您可能希望使用一个库,例如优秀的 JQuery,但是您不必这样做: 所有现代浏览器都通过 请求 API在其 JavaScript 实现中非常好地支持 HTTP,尽管它的名字不限于 XML 表示。
下面是用 JavaScript 发出同步 HTTP PUT 请求的一个例子:
var url = "http://host/path/to/resource";
var representationOfDesiredState = "The cheese is old and moldy, where is the bathroom?";
var client = new XMLHttpRequest();
client.open("PUT", url, false);
client.setRequestHeader("Content-Type", "text/plain");
client.send(representationOfDesiredState);
if (client.status == 200)
alert("The request succeeded!\n\nThe response representation was:\n\n" + client.responseText)
else
alert("The request did not succeed!\n\nThe response status was: " + client.status + " " + client.statusText + ".");
var client = new $.RestClient('/api/rest/');
client.add('foo');
client.foo.add('baz');
client.add('bar');
client.foo.create({a:21,b:42});
// POST /api/rest/foo/ (with data a=21 and b=42)
client.foo.read();
// GET /api/rest/foo/
client.foo.read("42");
// GET /api/rest/foo/42/
client.foo.update("42");
// PUT /api/rest/foo/42/
client.foo.delete("42");
// DELETE /api/rest/foo/42/
//RESULTS USE '$.Deferred'
client.foo.read().success(function(foos) {
alert('Hooray ! I have ' + foos.length + 'foos !' );
});