1- #Universal HTTP(S) Request for Catberry 2 [ ![ Build Status] ( https://travis-ci.org/catberry/catberry-uhr.png?branch=master )] ( https://travis-ci.org/catberry/catberry-uhr ) [ ![ Coverage Status] ( https://coveralls.io/repos/catberry/catberry-uhr/badge.png?branch=master )] ( https://coveralls.io/r/catberry/catberry-uhr?branch=master ) [ ![ Codacy Badge ] ( https://www.codacy.com/project/badge/5576b3df3def4b769978b42818ad96bc )] ( https://www.codacy.com/public/catberry/catberry-uhr.git )
1+ #Universal HTTP(S) Request for Catberry [ ![ Build Status] ( https://travis-ci.org/catberry/catberry-uhr.png?branch=master )] ( https://travis-ci.org/catberry/catberry-uhr ) [ ![ Coverage Status] ( https://coveralls.io/repos/catberry/catberry-uhr/badge.png?branch=master )] ( https://coveralls.io/r/catberry/catberry-uhr?branch=master )
22[ ![ NPM] ( https://nodei.co/npm/catberry-uhr.png )] ( https://nodei.co/npm/catberry-uhr/ )
33
44##Description
@@ -30,49 +30,81 @@ UHR has following methods:
3030/**
3131 * Does GET request to HTTP server.
3232 * @param {string} url URL to request.
33- * @param {Object} options Object with options.
33+ * @param {Object?} options Request parameters.
34+ * @param {Object?} options.headers HTTP headers to send.
35+ * @param {String|Object?} options.data Data to send.
36+ * @param {Number?} options.timeout Request timeout.
37+ * @param {Boolean?} options.unsafeHTTPS If true then requests to servers with
38+ * invalid HTTPS certificates are allowed.
3439 * @returns {Promise<Object>} Promise for result with status object and content.
3540 */
36- UHRBase .prototype .get = function (url , options ) { };
41+ UHRBase .prototype .get = function (url , options ) { }
3742
3843/**
3944 * Does POST request to HTTP server.
4045 * @param {string} url URL to request.
41- * @param {Object} options Object with options.
46+ * @param {Object?} options Request parameters.
47+ * @param {Object?} options.headers HTTP headers to send.
48+ * @param {String|Object?} options.data Data to send.
49+ * @param {Number?} options.timeout Request timeout.
50+ * @param {Boolean?} options.unsafeHTTPS If true then requests to servers with
51+ * invalid HTTPS certificates are allowed.
4252 * @returns {Promise<Object>} Promise for result with status object and content.
4353 */
44- UHRBase .prototype .post = function (url , options ) { };
54+ UHRBase .prototype .post = function (url , options ) { }
4555
4656/**
4757 * Does PUT request to HTTP server.
4858 * @param {string} url URL to request.
49- * @param {Object} options Object with options.
59+ * @param {Object?} options Request parameters.
60+ * @param {Object?} options.headers HTTP headers to send.
61+ * @param {String|Object?} options.data Data to send.
62+ * @param {Number?} options.timeout Request timeout.
63+ * @param {Boolean?} options.unsafeHTTPS If true then requests to servers with
64+ * invalid HTTPS certificates are allowed.
5065 * @returns {Promise<Object>} Promise for result with status object and content.
5166 */
52- UHRBase .prototype .put = function (url , options ) { };
67+ UHRBase .prototype .put = function (url , options ) { }
5368
5469/**
5570 * Does PATCH request to HTTP server.
5671 * @param {string} url URL to request.
57- * @param {Object} options Object with options.
72+ * @param {Object?} options Request parameters.
73+ * @param {Object?} options.headers HTTP headers to send.
74+ * @param {String|Object?} options.data Data to send.
75+ * @param {Number?} options.timeout Request timeout.
76+ * @param {Boolean?} options.unsafeHTTPS If true then requests to servers with
77+ * invalid HTTPS certificates are allowed.
5878 * @returns {Promise<Object>} Promise for result with status object and content.
5979 */
60- UHRBase .prototype .patch = function (url , options ) { };
80+ UHRBase .prototype .patch = function (url , options ) { }
6181
6282/**
6383 * Does DELETE request to HTTP server.
6484 * @param {string} url URL to request.
65- * @param {Object} options Object with options.
85+ * @param {Object?} options Request parameters.
86+ * @param {Object?} options.headers HTTP headers to send.
87+ * @param {String|Object?} options.data Data to send.
88+ * @param {Number?} options.timeout Request timeout.
89+ * @param {Boolean?} options.unsafeHTTPS If true then requests to servers with
90+ * invalid HTTPS certificates are allowed.
6691 * @returns {Promise<Object>} Promise for result with status object and content.
6792 */
68- UHRBase .prototype .delete = function (url , options ) { };
93+ UHRBase .prototype .delete = function (url , options ) { }
6994
7095/**
7196 * Does request with specified parameters.
7297 * @param {Object} parameters Request parameters.
98+ * @param {String} parameters.method HTTP method.
99+ * @param {String} parameters.url URL for request.
100+ * @param {Object?} parameters.headers HTTP headers to send.
101+ * @param {String|Object?} parameters.data Data to send.
102+ * @param {Number?} parameters.timeout Request timeout.
103+ * @param {Boolean?} parameters.unsafeHTTPS If true then requests
104+ * to servers with invalid HTTPS certificates are allowed.
73105 * @returns {Promise<Object>} Promise for result with status object and content.
74106 */
75- UHRBase .prototype .request = function (parameters ) { };
107+ UHRBase .prototype .request = function (parameters ) { }
76108```
77109
78110##Request options example
@@ -91,11 +123,17 @@ UHRBase.prototype.request = function (parameters) { };
91123}
92124```
93125
94- In case you do ` POST ` /` PUT ` /` PATCH ` request ` data ` will be passed as
95- JSON via request stream otherwise it will be passed as query string.
96- Also if you put something to ` data ` field and use
126+ In case you do ` POST ` /` PUT ` /` PATCH ` requests then ` data ` object will
127+ be passed as ` application/x-www-form-urlencoded ` via request stream.
128+ If you set header ` Content-Type ` to ` application/json ` then object will
129+ be sent as JSON.
130+
131+ If ` data ` value is not an object then its string representation will be sent
132+ as ` text/plain ` to server.
133+
134+ Also if you put something to ` data ` object and use
97135` application/x-www-form-urlencoded ` then this data will be
98- automatically [ encoded] ( https ://developer.mozilla .org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent ) .
136+ automatically [ percent- encoded] ( http ://en.wikipedia .org/wiki/Percent-encoding ) .
99137
100138##Returns promise
101139Any UHR request returns [ Promise] ( https://www.promisejs.org ) for request result.
0 commit comments