Skip to content

Commit 2d15b86

Browse files
author
Sefa Ilkimen
committed
add documentation for feature silkimen#77
1 parent 63d859a commit 2d15b86

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.11.0
4+
5+
- Feature #77: allow overriding global settings for each single request
6+
37
## 1.10.2
48

59
- Fixed #78: overriding header "Content-Type" not working on Android

README.md

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ If set to `true`, it won't follow redirects automatically. This is a global sett
100100
cordova.plugin.http.disableRedirect(true);
101101
```
102102

103-
### setDataSerializer
103+
### setDataSerializer<a name="setDataSerializer"></a>
104104
Set the data serializer which will be used for all future PATCH, POST and PUT requests. Takes a string representing the name of the serializer.
105105

106106
```js
@@ -183,6 +183,42 @@ Remove all cookies associated with a given URL.
183183
cordova.plugin.http.removeCookies(url, callback);
184184
```
185185

186+
### sendRequest
187+
Execute a HTTP request. Takes a URL and an options object. This is the internally used implementation of the following shorthand functions ([post](#post), [get](#get), [put](#put), [patch](#patch), [delete](#delete), [head](#head), [uploadFile](#uploadFile) and [downloadFile](#downloadFile)). You can use this function, if you want to override global settings for each single request.
188+
189+
The options object contains following keys:
190+
191+
* `method`: HTTP method to be used, defaults to `get`, needs to be one of the following values:
192+
* `get`, `post`, `put`, `patch`, `head`, `delete`, `upload`, `download`
193+
* `data`: payload to be send to the server (only applicable on `post`, `put` or `patch` methods)
194+
* `params`: query params to be appended to the URL (only applicable on `get`, `head`, `delete`, `upload` or `download` methods)
195+
* `serializer`: data serializer to be used (only applicable on `post`, `put` or `patch` methods), defaults to global serializer value, see [setDataSerializer](#setDataSerializer) for supported values
196+
* `timeout`: timeout value for the request in seconds, defaults to global timeout value
197+
* `headers`: headers object (key value pair), will be merged with global values
198+
* `filePath`: filePath to be used during upload and download see [uploadFile](#uploadFile) and [downloadFile](#downloadFile) for detailed information
199+
* `name`: name to be used during upload see [uploadFile](#uploadFile) for detailed information
200+
201+
Here's a quick example:
202+
203+
```js
204+
const options = {
205+
method: 'post',
206+
data: { id: 12, message: 'test' },
207+
headers: { Authorization: 'OAuth2: token' }
208+
};
209+
210+
cordova.plugin.http.sendRequest('https://google.com/', options, function(response) {
211+
// prints 200
212+
console.log(response.status);
213+
}, function(response) {
214+
// prints 403
215+
console.log(response.status);
216+
217+
//prints Permission denied
218+
console.log(response.error);
219+
});
220+
```
221+
186222
### post<a name="post"></a>
187223
Execute a POST request. Takes a URL, data, and headers.
188224

@@ -241,7 +277,7 @@ Here's a quick example:
241277
}
242278
```
243279

244-
### get
280+
### get<a name="get"></a>
245281
Execute a GET request. Takes a URL, parameters, and headers. See the [post](#post) documentation for details on what is returned on success and failure.
246282

247283
```js
@@ -255,19 +291,19 @@ cordova.plugin.http.get('https://google.com/', {
255291
});
256292
```
257293

258-
### put
294+
### put<a name="put"></a>
259295
Execute a PUT request. Takes a URL, data, and headers. See the [post](#post) documentation for details on what is returned on success and failure.
260296

261-
### patch
297+
### patch<a name="patch"></a>
262298
Execute a PATCH request. Takes a URL, data, and headers. See the [post](#post) documentation for details on what is returned on success and failure.
263299

264-
### delete
300+
### delete<a name="delete"></a>
265301
Execute a DELETE request. Takes a URL, parameters, and headers. See the [post](#post) documentation for details on what is returned on success and failure.
266302

267-
### head
303+
### head<a name="head"></a>
268304
Execute a HEAD request. Takes a URL, parameters, and headers. See the [post](#post) documentation for details on what is returned on success and failure.
269305

270-
### uploadFile
306+
### uploadFile<a name="uploadFile"></a>
271307
Uploads a file saved on the device. Takes a URL, parameters, headers, filePath, and the name of the parameter to pass the file along as. See the [post](#post) documentation for details on what is returned on success and failure.
272308

273309
```js
@@ -281,7 +317,7 @@ cordova.plugin.http.uploadFile("https://google.com/", {
281317
});
282318
```
283319

284-
### downloadFile
320+
### downloadFile<a name="downloadFile"></a>
285321
Downloads a file and saves it to the device. Takes a URL, parameters, headers, and a filePath. See [post](#post) documentation for details on what is returned on failure. On success this function returns a cordova [FileEntry object](http://cordova.apache.org/docs/en/3.3.0/cordova_file_file.md.html#FileEntry).
286322

287323
```js

0 commit comments

Comments
 (0)