# HttpProtect.middleware() method · @imqueue/http-protect

Source: https://imqueue.org/api/http-protect/latest/http-protect.httpprotect.middleware/
Published: 2026-08-01
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/http-protect 3.0.1 — generated reference, not hand-written

A middleware that rejects with a bare status code and no body.

**Signature:**

```typescript
middleware(): (req: Request, res: Response, next: NextFunction) => Promise<void>;
```
**Returns:**

(req: Request, res: [Response](https://imqueue.org/api/http-protect/latest/http-protect.response/), next: [NextFunction](https://imqueue.org/api/http-protect/latest/http-protect.nextfunction/)) => Promise<void>

An async middleware to hand to `app.use()`.

## Remarks

The leanest of the three: a rejected request gets its status and [Response.end()](https://imqueue.org/api/http-protect/latest/http-protect.response.end/), with no `Content-Type` and nothing written. Prefer [HttpProtect.jsonMiddleware()](https://imqueue.org/api/http-protect/latest/http-protect.httpprotect.jsonmiddleware/) for an API whose clients parse errors, or [HttpProtect.textMiddleware()](https://imqueue.org/api/http-protect/latest/http-protect.httpprotect.textmiddleware/) for something a human might read.

Mount it first, before body parsing and routing, so a rejected request costs as little as possible.

## Example


```typescript
app.use(new HttpProtect().middleware());
```

