forked from cujojs/rest
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rest.js
72 lines (63 loc) · 2.56 KB
/
rest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Copyright 2012-2013 the original author or authors
* @license MIT, see LICENSE.txt for details
*
* @author Scott Andrews
*/
(function (define, process) {
'use strict';
define(function (require) {
var moduleId;
/**
* Plain JS Object containing properties that represent an HTTP request.
*
* Depending on the capabilities of the underlying client, a request
* may be cancelable. If a request may be canceled, the client will add
* a canceled flag and cancel function to the request object. Canceling
* the request will put the response into an error state.
*
* @field {string} [method='GET'] HTTP method, commonly GET, POST, PUT, DELETE or HEAD
* @field {string|UrlBuilder} [path=''] path template with optional path variables
* @field {Object} [params] parameters for the path template and query string
* @field {Object} [headers] custom HTTP headers to send, in addition to the clients default headers
* @field [entity] the HTTP entity, common for POST or PUT requests
* @field {boolean} [canceled] true if the request has been canceled, set by the client
* @field {Function} [cancel] cancels the request if invoked, provided by the client
* @field {Client} [originator] the client that first handled this request, provided by the interceptor
*
* @class Request
*/
/**
* Plain JS Object containing properties that represent an HTTP response
*
* @field {Object} [request] the request object as received by the root client
* @field {Object} [raw] the underlying request object, like XmlHttpRequest in a browser
* @field {number} [status.code] status code of the response (i.e. 200, 404)
* @field {string} [status.text] status phrase of the response
* @field {Object] [headers] response headers hash of normalized name, value pairs
* @field [entity] the response body
*
* @class Response
*/
/**
* HTTP client particularly suited for RESTful operations.
*
* @field {function} chain wraps this client with a new interceptor returning the wrapped client
*
* @param {Request} the HTTP request
* @returns {Promise<Response>} a promise the resolves to the HTTP response
*
* @class Client
*/
if (process && process.versions && process.versions.node) {
// evade build tools
moduleId = './client/node';
return require(moduleId);
}
return require('./client/xhr');
});
}(
typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); },
typeof process === 'undefined' ? undefined : process
// Boilerplate for AMD and Node
));