Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#965]: Document other body types #1285

Merged
merged 2 commits into from Dec 12, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 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:
doug-wade marked this conversation as resolved.
Show resolved Hide resolved

```
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