Improved superagent.md with more properties
- Better identation - Markdown with correct syntax highlighting - Comment for every property - Added more properties (with examples)
This commit is contained in:
parent
f8fe256b03
commit
76b013411a
|
@ -1,35 +1,61 @@
|
|||
---
|
||||
title: Superagent
|
||||
category: JavaScript libraries
|
||||
updated: 2018-04-21
|
||||
prism_languages: [javascript]
|
||||
tags:
|
||||
- WIP
|
||||
---
|
||||
|
||||
### Result
|
||||
### Response object
|
||||
```javascript
|
||||
res: {
|
||||
// The HTTP Status Code (see: httpstatuses.com for definitions on HTTP status codes)
|
||||
status: 202,
|
||||
// True when res.status is 2xx
|
||||
ok: true,
|
||||
// True when res.status is 4xx or 5xx
|
||||
error: false,
|
||||
// True when res.status is 4xx
|
||||
clientError: false,
|
||||
// True when res.status is 5xx
|
||||
serverError: false,
|
||||
|
||||
result == {
|
||||
ok: true
|
||||
error: false
|
||||
// True when res.status == 202
|
||||
accepted: true,
|
||||
// True when res.status == 204 || res.status == 1223
|
||||
noContent: false,
|
||||
// True when res.status == 400
|
||||
badRequest: false,
|
||||
// True when res.status == 401
|
||||
unauthorized: false,
|
||||
// True when res.status == 406
|
||||
notAcceptable: false,
|
||||
// True when res.status == 404
|
||||
notFound: false,
|
||||
// True when res.status == 403
|
||||
forbidden: false,
|
||||
|
||||
// Response
|
||||
body: null
|
||||
text: "<!doctype html>..."
|
||||
// Unparsed response text
|
||||
text: '{"user":{"username":"JohnDoe","role":"admin"}}'
|
||||
|
||||
// Headers
|
||||
status: 200
|
||||
type: "text/html"
|
||||
charset: "UTF-8"
|
||||
headers: {
|
||||
'cache-control': 'public',
|
||||
'content-type': 'text/html; charset=UTF-8'
|
||||
// Parsed response text (only if response is 'application/json' or 'application/x-www-form-urlencoded'
|
||||
body: {
|
||||
// Example of parsed object from res.text
|
||||
user: {
|
||||
username: 'JohnDoe',
|
||||
role: 'admin'
|
||||
}
|
||||
|
||||
accepted: false
|
||||
|
||||
// specific errors
|
||||
badRequest: false
|
||||
clientError: false
|
||||
forbidden: false
|
||||
notFound: false
|
||||
noContent: false
|
||||
notAcceptable: false
|
||||
unauthorized: false
|
||||
}
|
||||
|
||||
// The content-type (parsed from headers)
|
||||
type: 'application/json'
|
||||
// The charset (parsed from headers)
|
||||
charset: 'UTF-8'
|
||||
// Header object with each header field as a property
|
||||
headers: {
|
||||
'content-type': 'application/json; charset=UTF-8',
|
||||
...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue