1 | /*
|
2 | * Copyright (c) 2012 VMware, Inc. All Rights Reserved.
|
3 | *
|
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
5 | * of this software and associated documentation files (the "Software"), to
|
6 | * deal in the Software without restriction, including without limitation the
|
7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
8 | * sell copies of the Software, and to permit persons to whom the Software is
|
9 | * furnished to do so, subject to the following conditions:
|
10 | *
|
11 | * The above copyright notice and this permission notice shall be included in
|
12 | * all copies or substantial portions of the Software.
|
13 | *
|
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
20 | * IN THE SOFTWARE.
|
21 | */
|
22 |
|
23 | (function (define, process) {
|
24 | ;
|
25 |
|
26 | define(function (require) {
|
27 |
|
28 | var moduleId;
|
29 |
|
30 | /**
|
31 | * Plain JS Object containing properties that represent an HTTP request.
|
32 | *
|
33 | * Depending on the capabilities of the underlying client, a request
|
34 | * may be cancelable. If a request may be canceled, the client will add
|
35 | * a canceled flag and cancel function to the request object. Canceling
|
36 | * the request will put the response into an error state.
|
37 | *
|
38 | * @field {string} [method='GET'] HTTP method, commonly GET, POST, PUT, DELETE or HEAD
|
39 | * @field {string|UrlBuilder} [path=''] path template with optional path variables
|
40 | * @field {Object} [params] parameters for the path template and query string
|
41 | * @field {Object} [headers] custom HTTP headers to send, in addition to the clients default headers
|
42 | * @field [entity] the HTTP entity, common for POST or PUT requests
|
43 | * @field {boolean} [canceled] true if the request has been canceled, set by the client
|
44 | * @field {Function} [cancel] cancels the request if invoked, provided by the client
|
45 | *
|
46 | * @class Request
|
47 | */
|
48 |
|
49 | /**
|
50 | * Plain JS Object containing properties that represent an HTTP response
|
51 | *
|
52 | * @field {Object} [request] the request object as received by the root client
|
53 | * @field {Object} [raw] the underlying request object, like XmlHttpRequest in a browser
|
54 | * @field {number} [status.code] status code of the response (i.e. 200, 404)
|
55 | * @field {string} [status.text] status phrase of the response
|
56 | * @field {Object] [headers] response headers hash of normalized name, value pairs
|
57 | * @field [entity] the response body
|
58 | *
|
59 | * @class Response
|
60 | */
|
61 |
|
62 | /**
|
63 | * HTTP client particularly suited for RESTful operations.
|
64 | *
|
65 | * @param {Request} the HTTP request
|
66 | * @returns {Promise<Response>} a promise the resolves to the HTTP response
|
67 | *
|
68 | * @class Client
|
69 | */
|
70 |
|
71 | if (process && process.versions && process.versions.node) {
|
72 | // avaid build tools
|
73 | moduleId = './client/node';
|
74 | return require(moduleId);
|
75 | }
|
76 |
|
77 | return require('./client/xhr');
|
78 | });
|
79 |
|
80 | }(
|
81 | typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); },
|
82 | typeof process === 'undefined' ? undefined : process
|
83 | // Boilerplate for AMD and Node
|
84 | ));
|