ctx.request.query

A parsed object of query string parameters for the current request.

Since Koa 2 Spec ↗

Syntax

ctx.request.query  // or ctx.query

Returns

Record<string, string | string[]> — Parsed query parameters as a plain object; always returns an object (never throws).

Examples

import Koa from 'koa';

const app = new Koa();

app.use(async (ctx) => {
  // GET /search?q=koa&page=2&tags=js&tags=web
  const { q, page = '1', tags } = ctx.query;
  ctx.body = { q, page: Number(page), tags };
});

app.listen(3000);
Output
{"q":"koa","page":2,"tags":["js","web"]}

Notes

`ctx.query` is writable; assigning an object updates the query string portion of `ctx.url`. Values are always strings (or arrays of strings); parse/coerce them yourself. For the raw query string, use `ctx.querystring`. Uses `querystring.parse()` internally.

See also