request (NodeJS http client) API using jQuery back-end
Switch branches/tags
Nothing to show
Pull request Compare This branch is 2 commits behind iriscouch:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

jQuery Request: The easiest HTTP library you'll ever see

jQuery Request is a port of Mikeal Rogers's excellent request library to the browser.

If you are secretly jealous of NodeJS people with their clever callbacks and no-nonsense APIs, jQuery Request is for you.

If you don't care about NodeJS, but simply want less tedium and verbosity for your AJAX code, jQuery Request is for you too.


GET a resource:

$.request('/some/resource.txt', function(er, resp, body) {
    throw er;
  console.log("I got: " + body);

PUT a resource:

$.request.put({uri:'/some/resource.xml', body:'<foo><bar/></foo>'}, function(er, resp, body) {
    throw new Error("XML PUT failed (" + er + "): HTTP status was " + resp.status);
  console.log("Stored the XML");

To work with JSON, $.request.json will conveniently set the Content-Type and Accept headers, and handle parsing and serialization.

$.request.json({method:'POST', url:'/db/', json:{"relaxed":true}, function(er, resp, result) {
    throw er;

    console.log('Server ok, id = ' +;

Convenient CouchDB

Finally, jQuery Request provides a CouchDB wrapper. It is the same as the JSON wrapper, however it will indicate an error if the HTTP query was fine, but there was a problem at the database level. The most common example is 409 Conflict.

$.request.couch({method:'PUT', url:'/db/existing_doc', json:{"will_conflict":"you bet!"}, function(er, resp, result) {
    return console.error("Couch said no: " + er.reason); // Output: Couch said no: Document update conflict.

    throw er;

  console.log("Existing doc stored. This must have been the first run.");

See the NodeJS Request README for several more examples. jQuery Request intends to maintain feature parity with Node request (except what the browser disallows). If you find a discrepancy, please submit a bug report. Thanks!


The traditional way is to reference it like any other Javascript library.

<script src=""></script>
<script src="request.jquery.js"></script>

jQuery Request also supports RequireJS.

define(['request.jquery'], function(request) {
  // `request` is ready