Skip to content

Commit 96dbe6b

Browse files
author
Philippe Masset
committed
Add documentation to methods
1 parent 27bae0d commit 96dbe6b

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

Request.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22
* Interface to send requests – thin wrapper around fetch()
33
*
44
* send, get and post return a Promise that resolves with a Response object
5-
* from which can be retrieved Body's contents.
5+
* from which can be retrieved Body's contents. They all receive the same params:
6+
*
7+
* @param {string} url - relative URL of the API endpoint, e.g. 'updates/create.json'
8+
* @param {object} [data] - any piece of data to send alongside the request
9+
* @param {object} [settings] - any additional options to pass to GlobalFetch.fetch()
10+
*
11+
* Note: This util encodes data according to the multipart/form-data type, since that's
12+
* what most of our current endpoints expect, and it plays well with PHP. For newer
13+
* endpoints, esp. Node ones, it might make more sense to JSON.stringify() the data object
14+
* and pass it as a string through settings.body, and JSON.parse() that payload on
15+
* the server. Additions welcome!
616
*/
717

818
class Request {
@@ -51,13 +61,15 @@ class Request {
5161

5262
/**
5363
* Split non-primitive values into primitive chunks with formatted keys to be used
54-
* with FormData.append
64+
* with FormData.append()
5565
*
56-
* data is an array of primitives, arrays and objects
66+
* @param {object} [data] - map of primitives, arrays and objects
5767
*
58-
* Example:
68+
* E.g.:
5969
* formatDataPieces({ values: [{ a: 'a', b: 'b' }] })
6070
* => [ ['values[0][a]', 'a'], ['values[0][b]', 'b'] ]
71+
*
72+
* TODO: Add tests
6173
*/
6274
function formatDataPieces(data) {
6375
const dataPieces = [];

0 commit comments

Comments
 (0)