HTTP Post footprint change
No we require either a body, or a null/undefined Closes #520
This commit is contained in:
@ -10,7 +10,7 @@ Omit the third argument, `data`, to send no data to the provided `url`.
|
|||||||
Omit the fourth argument, `err`, to log errors to the console's `error` stream by default.
|
Omit the fourth argument, `err`, to log errors to the console's `error` stream by default.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const httpPost = (url, callback, data = null, err = console.error) => {
|
const httpPost = (url, data, callback, err = console.error) => {
|
||||||
const request = new XMLHttpRequest();
|
const request = new XMLHttpRequest();
|
||||||
request.open('POST', url, true);
|
request.open('POST', url, true);
|
||||||
request.setRequestHeader('Content-type', 'application/json; charset=utf-8');
|
request.setRequestHeader('Content-type', 'application/json; charset=utf-8');
|
||||||
@ -30,8 +30,8 @@ const newPost = {
|
|||||||
const data = JSON.stringify(newPost);
|
const data = JSON.stringify(newPost);
|
||||||
httpPost(
|
httpPost(
|
||||||
'https://jsonplaceholder.typicode.com/posts',
|
'https://jsonplaceholder.typicode.com/posts',
|
||||||
console.log,
|
data,
|
||||||
data
|
console.log
|
||||||
); /*
|
); /*
|
||||||
Logs: {
|
Logs: {
|
||||||
"userId": 1,
|
"userId": 1,
|
||||||
@ -40,4 +40,13 @@ Logs: {
|
|||||||
"body": "bar bar bar"
|
"body": "bar bar bar"
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
httpPost(
|
||||||
|
'https://jsonplaceholder.typicode.com/posts',
|
||||||
|
null,
|
||||||
|
console.log
|
||||||
|
); /*
|
||||||
|
Logs: {
|
||||||
|
"id": 101
|
||||||
|
}
|
||||||
|
*/
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user