-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrequest.node.txt
60 lines (58 loc) · 4.78 KB
/
request.node.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
┏━━━━━━━━━━━━━┓
┃ REQUEST ┃
┗━━━━━━━━━━━━━┛
REQUEST[.METHOD](URL|OBJ #Node module (2.37.0). Make a HTTP[S] request.
[,FUNC(ERROR, REQ, VAL)]) #REQ is response (like HTTP.request() event handler).
#VAL is response body (STR|BUFFER, or OBJ if json OBJ|true)
#OBJ (can set defaults with REQUEST.defaults(OBJ)):
# - url STR|URL_OBJ (from URL.parse())
# Must include protocol.
# Supports unix://FILE/PATH as a protocol + domain name.
# - qs OBJ: GET variables
# - method STR: or .METHOD ("del" for "delete") (def: "GET")
# - headers OBJ: by default, only host, content-length (if body|json), connection: keep-alive
# - body STR|BUFFER: non-OBJ request body
# - json OBJ|BOOL: OBJ request|response body:
# - if true|OBJ: Accept: application/json, and parse response body as OBJ
# - if OBJ: Content-Type: application/json, and sends OBJ in response body
# - encoding STR: of response. If null, BUFFER, otherwise response STR (def)
# - gzip true: adds accept-encoding: gzip [C]
# - pool.maxSockets UINT: AGENT.maxSockets (def: same as GLOBALAGENT)
# - auth OBJ (can also use REQIOSTREAM.auth(STR, STR2, BOOL, STR3):
# - username|password STR
# - sendImmediately BOOL: if true (def), only do HTTP Basic auth.
# If false, start trying Basic auth., and if get response 401 with WWW-Authenticate header,
# try another authentication method (like Digest or Bearer)
# - bearerToken STR3: for HTTP Bearer auth., like OAuth2
# - oauth OBJ (HMAC-SHA1) (OAuth1):
# - consumer_key CLIENT_KEY
# - consumer_secret CLIENT_SECRET
# - callback APP_URL
# - token TOKEN_STR
# - token_secret
# - verifier
# - hawk OBJ: Hawk authentication
# - httpSignature OBJ: Joyent HTTP Signature authentication
# - timeout NUM: ERROR has code 'ETIMEDOUT'
# - follow[All]Redirects BOOL (def: true): follow 3xx|all redirections.
# - maxRedirects NUM (def: 10)
# - proxy URL: can use HTTP Basic Auth. by putting USERNAME:PASSWORD in the URL
# - localAddress URL
# - strictSSL BOOL (def: false): verify certificates
# - jar VAL: if false (def), disable cookies.
# If VAL is REQUEST.jar(), use it as a store of cookies. If true, use the default one.
# Can use JAR.setCookie(VAR, VAL) and JAR.getCookie[s|String](URI)
#Returns REQIOSTREAM:
# - can pipe ISTREAM to REQIOSTREAM, which will write request body to REQIOSTREAM:
# - Only works with methods like PUT, POST, etc.
# - If ISTREAM.path present (e.g. with FS.createReadStream()), sets content-type header
# according to extension
# - If ISTREAM is REQ, sets REQ HTTP methods and headers to REQIOSTREAM
# - can pipe REQIOSTREAM to OSTREAM, which will write response to OSTREAM:
# - If OSTREAM is RES, sets request() response's HTTP methods and headers to RES
REQIOSTREAM.form(OBJ) #Adds request body application/x-www-form-urlencoded data. Can use several depth in OBJ
#("VAR[VAR2]=VAL&...", see QS)
#Can also use OBJ2.form OBJ in FUNC() above
REQIOSTREAM.form() #Adds request body multipart/form-data.
.append(VAR_STR, VAL) #VAL can be STR, BUFFER, ISTREAM (including REQIOSTREAM or RES)
#Sets up Content-Disposition and, if ISTREAM, filename="..." and Content-Type