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
|
title: Superagent
|
||||||
category: JavaScript libraries
|
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 == {
|
// True when res.status == 202
|
||||||
ok: true
|
accepted: true,
|
||||||
error: false
|
// 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
|
// Unparsed response text
|
||||||
body: null
|
text: '{"user":{"username":"JohnDoe","role":"admin"}}'
|
||||||
text: "<!doctype html>..."
|
|
||||||
|
|
||||||
// Headers
|
// Parsed response text (only if response is 'application/json' or 'application/x-www-form-urlencoded'
|
||||||
status: 200
|
body: {
|
||||||
type: "text/html"
|
// Example of parsed object from res.text
|
||||||
charset: "UTF-8"
|
user: {
|
||||||
headers: {
|
username: 'JohnDoe',
|
||||||
'cache-control': 'public',
|
role: 'admin'
|
||||||
'content-type': 'text/html; charset=UTF-8'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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