UNPKG

1.78 kBJavaScriptView Raw
1(function (define, process) {
2
3 define(['./client/xhr'], function (client) {
4 "use strict";
5
6 /**
7 * Plain JS Object containing properties that represent an HTTP request
8 *
9 * @field {String} [method='GET'] HTTP method, commonly GET, POST, PUT, DELETE or HEAD
10 * @field {String|UrlBuilder} [path=''] path template with optional path variables
11 * @field {Object} [params] parameters for the path template and query string
12 * @field {Object} [headers] custom HTTP headers to send, in addition to the clients default headers
13 * @field {*} [entity] the HTTP entity, common for POST or PUT requests
14 *
15 * @class Request
16 */
17
18 /**
19 * Plain JS Object containing properties that represent an HTTP response
20 *
21 * @field {Object} [request] the request object as received by the root client
22 * @field {Object} [raw] the underlying request object, like XmlHttpRequest in a browser
23 * @field {Number} [status.code] status code of the response (i.e. 200, 404)
24 * @field {String} [status.text] status phrase of the response
25 * @field {Object] [headers] response headers hash of normalized name, value pairs
26 * @field {*} [entity] the response body
27 *
28 * @class Response
29 */
30
31 /**
32 * HTTP client particularly suited for RESTful operations.
33 *
34 * @param {Request} the HTTP request
35 * @returns {Promise<Response>} a promise the resolves to the HTTP response
36 *
37 * @class Client
38 */
39
40 if (process && process.versions && process.versions.node) {
41 return require('./client/node');
42 }
43
44 return client;
45 });
46
47}(
48 typeof define === 'function' ? define : function (deps, factory) {
49 module.exports = factory.apply(this, deps.map(require));
50 },
51 typeof process === 'undefined' ? undefined : process
52 // Boilerplate for AMD and Node
53));