ctx.request.type
The `Content-Type` of the request body, without parameters such as `; charset=utf-8`.
Syntax
ctx.request.type Returns
string — The MIME type string (e.g. `"application/json"`), or `""` if no Content-Type header is present.
Examples
import Koa from 'koa';
const app = new Koa();
app.use(async (ctx) => {
console.log(ctx.request.type);
// application/json (charset stripped)
ctx.body = { contentType: ctx.request.type };
});
app.listen(3000);
Output
# POST with Content-Type: application/json; charset=utf-8
application/json
Notes
This strips charset and boundary parameters — use `ctx.is()` for type
matching with wildcards, or read `ctx.get('content-type')` for the full
raw header value.