koa-override is a Koa middleware designed to enable clients to utilize HTTP verbs like PUT or DELETE in environments where direct support is limited, typically by overriding the method via a `_method` field in the request body or an `X-HTTP-Method-Override` header. The current stable version is 4.0.0, released in June 2024. This package is maintained by the Egg.js team, indicating active development and stability within the Koa ecosystem. It provides a simple API, `override([options])`, allowing configuration of allowed override methods (defaulting to `POST` requests). A key differentiator is its explicit method overriding mechanism, making it a robust solution for RESTful API compatibility challenges with legacy clients or specific network constraints. It ships with TypeScript types and supports both CommonJS and ES Modules since version 4.0.0.
npm install koa-overrideVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up a basic Koa application with `koa-override` and `koa-bodyparser` to allow method overriding via request body (`_method`) or HTTP header (`X-HTTP-Method-Override`).
Upgrade Node.js to version 18.19.0 or higher, or explicitly install `koa-override@3`.
Ensure `koa-bodyparser` or a similar body parser middleware is used *before* `koa-override` in your middleware chain: `app.use(bodyParser()); app.use(override());`
If you need to override methods on non-POST requests, configure `koa-override` with `app.use(override({ allowedMethods: ['POST', 'GET', 'PATCH'] }));`Change `app.use(override)` to `app.use(override())`.
Add a body parser middleware, like `koa-bodyparser`, before `koa-override`. Example: `app.use(bodyParser()); app.use(override());`
Configure `koa-override` with the `allowedMethods` option to include the desired request types, e.g., `app.use(override({ allowedMethods: ['POST', 'GET'] }));`No dependency data recorded yet.