# @gasket/request

> Utilities for working with request objects in Gasket

Latest version **7.6.1** (published 2026-09-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @gasket/request
pnpm add @gasket/request
yarn add @gasket/request
bun add @gasket/request
```

## Health

**Score 55/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 7.6.1 |
| Published | 2026-09-25 |
| First published | 2024-11-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 145 |
| Author | GoDaddy Operating Company, LLC |
| Maintainers | kinetifex, 3rdeden, kawikabader, mmason2, jpina1-godaddy, bbetts, ecarlson-godaddy, rxmarbles |
| Keywords | gasket, plugin, plugin-engine, preset |

## Links

- npm: https://www.npmjs.com/package/@gasket/request
- Repository: https://github.com/godaddy/gasket
- Homepage: https://github.com/godaddy/gasket/tree/main/packages/gasket-request
- Issues: https://github.com/godaddy/gasket/issues
- npm.io page: https://npm.io/package/@gasket/request

## Recent versions

- 7.6.1 (latest) — 2026-09-25
- 0.0.0-react19-20260205182644 (react19) — 2026-02-05
- 0.0.0-canary-20260205165418 (canary) — 2026-02-05
- 8.0.0-next.1 (next) — 2026-01-28
- 7.6.0 — 2026-09-23
- 7.5.6 — 2026-08-28
- 7.5.5 — 2025-12-19
- 0.0.0-canary-20251110223653 — 2025-11-10
- 0.0.0-canary-20251028184342 — 2025-10-28
- 0.0.0-canary-20251028154539 — 2025-10-28
- 0.0.0-canary-20251027203841 — 2025-10-27
- 0.0.0-canary-20251027201142 — 2025-10-27
- 0.0.0-canary-20251027184152 — 2025-10-27
- 0.0.0-canary-20251027182220 — 2025-10-27
- 0.0.0-canary-20251024194725 — 2025-10-24
- … 47 more at https://npm.io/package/@gasket/request/versions

## README

# @gasket/request

The purpose of this package is to provide a consistent request object for Gasket
plugins and apps to use, regardless of the request handling framework.

## Installation

#### Existing apps

```shell
npm install @gasket/request
```

## Functions

### GasketRequest

The `GasketRequest` class is a representation of a request object that can be
used by Gasket plugins and apps. It is a consistent shape that can be used
across different request handling frameworks.

A `GasketRequest` object has the following properties:

| Property | Type   | Description                | Arguments     |
|----------|--------|----------------------------|---------------|
| headers  | object | Request headers            | required      |
| cookies  | object | Request cookies            | default: `{}` |
| query    | object | Query parameters           | default: `{}` |
| path     | string | Request path               | default: `''` |
| method   | string | Request method, uppercased | optional      |

`method` is `undefined` when the source request exposes none. Most notably this
is the case in the Next.js App Router, where `next/headers` provides no method.
It is deliberately not defaulted to `GET`: a Server Action runs as a `POST` and
re-renders server components within that same request, so a default would be
wrong rather than merely imprecise.

### makeGasketRequest

A `GasketRequest` can be created from a Node `IncomingMessage` object, an
Express `Request` object, or a Next.js `NextRequest` object, amongst others.

```js
import { makeGasketRequest } from '@gasket/request';

export default async function expressHandler(req, res) {
  const gasketRequest = await makeGasketRequest(req);
  // use gasketRequest
}
```

You can also assemble a `GasketRequest` object from parts of a request object.

```js
import { makeGasketRequest } from '@gasket/request';

const headers = {
  'x-example': 'example'
};

const staticGasketRequest = await makeGasketRequest({ headers });
````

### getOriginalRequest

Returns the original framework request a `GasketRequest` was normalized from.
Use it to reach framework-specific fields that `GasketRequest` does not
normalize, such as `ip`.

```js
import { getOriginalRequest } from '@gasket/request';

const ip = getOriginalRequest(gasketRequest)?.ip;
```

Returns `undefined` when there is no original request — a directly constructed
`GasketRequest`, a serialized and revived one, or any absent value.

Treat the result as read-only. Do not mutate the request or consume its body: a
fetch `Request` or `IncomingMessage` body is a single-use stream, so reading it
here leaves nothing for the handler that reads it next, and the failure surfaces
far from this call.

In the Next.js App Router there is no request instance, so the returned value is
the request-like object assembled from `next/headers`. It is truthy but carries
only headers, cookies, and query. Guard the field you need, not the object. See
[EXAMPLES.md](./EXAMPLES.md#getoriginalrequest).

### withGasketRequest

A higher-order function that can wrap a GasketAction function and provides a
`GasketRequest` object as the first argument.
This provides an easy way to normalize the request object for any `GasketAction`
and potential lifecycle hooks.

```js
import { withGasketRequest } from '@gasket/request';

export const myAction = withGasketRequest(
  async function handler(gasket, gasketRequest) {
    // use gasketRequest
  }
);

// example usage
await gasket.actions.myAction(req);
```

If your action needs additional arguments, you can pass them following the `gasketReq`.

```js
import { withGasketRequest } from '@gasket/request';

export const myAction = withGasketRequest(
  async function handler(gasket, gasketRequest, arg1, arg2) {
    // use gasketRequest
  }
);

// example usage
await gasket.actions.myAction(req, true, false);
```

### withGasketRequestCache

Much like the previous function, `withGasketRequestCache` is a higher-order
function that wraps an action handler function and provides a `GasketRequest`.
The difference is the handler will only be triggered once per request, and the
result will be cached for subsequent calls.

```js
import { withGasketRequestCache } from '@gasket/request';

export const myAction = withGasketRequestCache(
  async function handler(gasket, gasketRequest, arg1, arg2) {
    // use gasketRequest
  }
);

// example usage
await gasket.actions.myAction(req, true, false);
```

## Purpose

Why do we need a request object for Gasket?

Some Gasket plugins and apps need to interact with the request object.
Unfortunately, the shape and details of a request object is not consistent
across all request handling frameworks.

For example:

- Node's `IncomingMessage` [docs](https://nodejs.org/api/http.html#http_class_http_incomingmessage)
- Express "enhances" this as `Request` [docs](https://expressjs.com/en/api.html#req)
  - Various other engines also do the same
- Next.js API's (including middleware) use `NextRequest` [docs](https://nextjs.org/docs/pages/api-reference/functions/next-request)
- This extends the browser-compatible Fetch `Request` [docs](https://developer.mozilla.org/en-US/docs/Web/API/Request)
- Next.js App Router does not expose the request object, so we make a representation with the parts available [docs](https://github.com/godaddy/gasket/blob/main/packages/gasket-nextjs/README.md#request)

And we are aware of apps using Gasket for Static Pages with Next.js,
assembling a request-like object to use with certain actions.

---
_Source: https://npm.io/package/@gasket/request · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
