From 57a77b21f5064180fba371fff392c54d94973360 Mon Sep 17 00:00:00 2001 From: Robert Mennell Date: Tue, 16 Jan 2018 10:05:29 -0800 Subject: [PATCH 1/2] HTTP Post footprint change No we require either a body, or a null/undefined Closes #520 --- snippets/httpPost.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/snippets/httpPost.md b/snippets/httpPost.md index 8b51b5fbe..2d9d363d9 100644 --- a/snippets/httpPost.md +++ b/snippets/httpPost.md @@ -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. ```js -const httpPost = (url, callback, data = null, err = console.error) => { +const httpPost = (url, data, callback, err = console.error) => { const request = new XMLHttpRequest(); request.open('POST', url, true); request.setRequestHeader('Content-type', 'application/json; charset=utf-8'); @@ -30,8 +30,8 @@ const newPost = { const data = JSON.stringify(newPost); httpPost( 'https://jsonplaceholder.typicode.com/posts', - console.log, - data + data, + console.log ); /* Logs: { "userId": 1, @@ -40,4 +40,13 @@ Logs: { "body": "bar bar bar" } */ +httpPost( + 'https://jsonplaceholder.typicode.com/posts', + null, + console.log +); /* +Logs: { + "id": 101 +} +*/ ``` From e20dc77e9c09995ddb4af039bf8fc3e8fa02ac4b Mon Sep 17 00:00:00 2001 From: Robert Mennell Date: Tue, 16 Jan 2018 10:09:52 -0800 Subject: [PATCH 2/2] Add comment to second example about body Explain that by providing null/undefined, we are telling it we are not sending a body(or specifically a lack there of) --- snippets/httpPost.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/httpPost.md b/snippets/httpPost.md index 2d9d363d9..502e1044e 100644 --- a/snippets/httpPost.md +++ b/snippets/httpPost.md @@ -42,7 +42,7 @@ Logs: { */ httpPost( 'https://jsonplaceholder.typicode.com/posts', - null, + null, //does not send a body console.log ); /* Logs: {