OSDN Git Service

Regular updates
[twpd/master.git] / superagent.md
1 ---
2 title: Superagent
3 category: JavaScript libraries
4 updated: 2018-04-21
5 prism_languages: [javascript]
6 tags:
7   - WIP
8 ---
9
10 ### Response object
11 ```javascript
12   res: {
13     // The HTTP Status Code (see: httpstatuses.com for definitions on HTTP status codes)
14     status: 202,
15     // True when res.status is 2xx
16     ok: true,
17     // True when res.status is 4xx or 5xx
18     error: false,
19     // True when res.status is 4xx
20     clientError: false,
21     // True when res.status is 5xx
22     serverError: false,
23
24     // True when res.status == 202
25     accepted: true,
26     // True when res.status == 204 || res.status == 1223 
27     noContent: false,
28     // True when res.status == 400
29     badRequest: false,
30     // True when res.status == 401
31     unauthorized: false,
32     // True when res.status == 406
33     notAcceptable: false,
34     // True when res.status == 404
35     notFound: false,
36     // True when res.status == 403
37     forbidden: false,
38
39     // Unparsed response text
40     text: '{"user":{"username":"JohnDoe","role":"admin"}}'
41
42     // Parsed response text (only if response is 'application/json' or 'application/x-www-form-urlencoded'
43     body: {
44       // Example of parsed object from res.text
45       user: {
46         username: 'JohnDoe',
47         role: 'admin'
48       }
49     }
50
51     // The content-type (parsed from headers)
52     type: 'application/json'
53     // The charset (parsed from headers)
54     charset: 'UTF-8'
55     // Header object with each header field as a property
56     headers: {
57       'content-type': 'application/json; charset=UTF-8',
58       ...
59     }
60 }
61 ```