ctx.request.path

The request pathname without the query string.

Since Koa 2 Spec ↗

Syntax

ctx.request.path  // or ctx.path

Returns

string — URL pathname, e.g. `"/api/users"`.

Examples

import Koa from 'koa';

const app = new Koa();

app.use(async (ctx) => {
  // GET /api/users?active=true
  console.log(ctx.path);  // /api/users
  ctx.body = { path: ctx.path };
});

app.listen(3000);
Output
{"path":"/api/users"}
// Simple manual routing without koa-router
app.use(async (ctx) => {
  if (ctx.method === 'GET' && ctx.path === '/health') {
    ctx.body = { status: 'ok' };
  } else {
    ctx.throw(404);
  }
});
Output
GET /health → {"status":"ok"}

Notes

`ctx.path` is writable; assigning it updates the underlying `ctx.url`. For full URL control (including rewriting query strings) assign to `ctx.url` directly. When using `koa-router`, matched route parameters are available via `ctx.params`.

See also