ctx.request.querystring

The raw query string from the URL, without the leading `?`.

Since Koa 2 Spec ↗

Syntax

ctx.request.querystring  // or ctx.querystring

Returns

string — Raw query string, e.g. `"page=2&sort=asc"`. Empty string when there is no query.

Examples

import Koa from 'koa';

const app = new Koa();

app.use(async (ctx) => {
  // GET /items?page=2&sort=asc
  ctx.body = {
    raw: ctx.querystring,       // "page=2&sort=asc"
    parsed: ctx.query,          // { page: '2', sort: 'asc' }
  };
});

app.listen(3000);
Output
{"raw":"page=2&sort=asc","parsed":{"page":"2","sort":"asc"}}

Notes

`ctx.querystring` is writable and updates the underlying URL. Prefer `ctx.query` for most use-cases; use `ctx.querystring` when you need the raw string for signing, logging, or forwarding to an upstream service.

See also