Serialize Response Body
.resolveWith(type)
| Parameter | Default | Description |
|---|---|---|
| type | "intelligent" | How to serialize response body |
Available values for type:
| Type | Description |
|---|---|
"intelligent" | If Middleware sets context.output, return context.output, otherwise automatically serialize the response body based on HTTP response Content-Type. |
"response" | Return Response object |
"text" | Return context.response.text() |
"json" | Return context.response.json() |
"form-data" | Return context.response.formData() |
"blob" | Return context.response.blob() |
"array-buffer" | Return context.response.arrayBuffer() |
Example
import { request } from 'keq'
const res = await request
.get('/cat')
.resolveWith('response')
const body = await res.json()
console.log(`Cat name is: ${body.name}`)