---
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',
+ ...
}
+}
+```