Skip to content

Commit

Permalink
docs: Document other body types (koajs#1285)
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-wade authored and kiku-jw committed Feb 26, 2019
1 parent 55431e6 commit a68f12f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/api/response.md
Expand Up @@ -124,6 +124,16 @@ so you can make a correction.

If `response.status` has not been set, Koa will automatically set the status to `200` or `204`.

Koa doesn't guard against everything that could be put as a response body -- a function doesn't serialise meaningfully, returning a boolean may make sense based on your application, and while an error works, it may not work as intended as some properties of an error are not enumerable. We recommend adding middleware in your app that asserts body types per app. A sample middleware might be:

```
app.use(async (ctx, next) => {
await next()
ctx.assert.equal('object', typeof ctx, 500, 'some dev did something wrong')
})
```

#### String

The Content-Type is defaulted to text/html or text/plain, both with
Expand Down

0 comments on commit a68f12f

Please sign in to comment.