-
Notifications
You must be signed in to change notification settings - Fork 16
/
r2.javascript.txt
30 lines (22 loc) · 2.25 KB
/
r2.javascript.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
R2
VERSION ==> #0.0.0-development (2017-11-20)
#Small wrapper around fetch(). Not enough reason to use at the moment.
FETCH-BASED ==> #Uses fetch():
# - in Node.js, requires node-fetch
# - in browser, must manually load a fetch polyfill like github/fetch
R2('URL'|OPTS)->R2I #OPTS:
# - url 'URL'
# - method STR (def: 'GET')
# - headers OBJ
# - body STR|BUFFER
# - json VAL: like body but calls JSON.stringify() and set Content-Type: application/json
# - rest are passed to fetch()
R2.put|get|post|head|patch|delete
(...) #Same with OPTS.method STR
R2I.json|text|arrayBuffer|blob|
formData #PROMISE(VAL) (rejected if fetch() PROMISE rejected)
R2I.setHeaders({ VAR: 'VAL' })
R2I.setHeader('VAR', 'VAL') #
R2I.response #Return value of fetch(), i.e. PROMISE(RES, ERROR)