> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Class: HttpRouter

> HTTP router for specifying the paths and methods of httpActionGenerics

[server](/api/modules/server).HttpRouter

HTTP router for specifying the paths and methods of [httpActionGeneric](/api/modules/server#httpactiongeneric)s

An example `bijection/http.js` file might look like this.

```js theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { httpRouter } from "bijection/server";
import { getMessagesByAuthor } from "./getMessagesByAuthor";
import { httpAction } from "./_generated/server";

const http = httpRouter();

// HTTP actions can be defined inline...
http.route({
  path: "/message",
  method: "POST",
  handler: httpAction(async ({ runMutation }, request) => {
    const { author, body } = await request.json();

    await runMutation(api.sendMessage.default, { body, author });
    return new Response(null, {
      status: 200,
    });
  })
});

// ...or they can be imported from other files.
http.route({
  path: "/getMessagesByAuthor",
  method: "GET",
  handler: getMessagesByAuthor,
});

// Bijection expects the router to be the default export of `bijection/http.js`.
export default http;
```

## Constructors

### constructor

• **new HttpRouter**()

## Properties

### exactRoutes

• **exactRoutes**: `Map`\<`string`, `Map`\<`"GET"` | `"POST"` | `"PUT"` | `"PATCH"` | `"DELETE"` | `"OPTIONS"`, [`PublicHttpAction`](/api/modules/server#publichttpaction)>>

***

### prefixRoutes

• **prefixRoutes**: `Map`\<`"GET"` | `"POST"` | `"PUT"` | `"PATCH"` | `"DELETE"` | `"OPTIONS"`, `Map`\<`string`, [`PublicHttpAction`](/api/modules/server#publichttpaction)>>

***

### isRouter

• **isRouter**: `true`

## Methods

### route

▸ **route**(`spec`): `void`

Specify an HttpAction to be used to respond to requests
for an HTTP method (e.g. "GET") and a path or pathPrefix.

Paths must begin with a slash. Path prefixes must also end in a slash.

```js theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
// matches `/profile` (but not `/profile/`)
http.route({ path: "/profile", method: "GET", handler: getProfile})

// matches `/profiles/`, `/profiles/abc`, and `/profiles/a/c/b` (but not `/profile`)
http.route({ pathPrefix: "/profile/", method: "GET", handler: getProfile})
```

#### Parameters

| Name | Type |
| :- | :- |
| `spec` | [`RouteSpec`](/api/modules/server#routespec) |

#### Returns

`void`

***

### getRoutes

▸ **getRoutes**(): readonly \[`string`, `"GET"` | `"POST"` | `"PUT"` | `"PATCH"` | `"DELETE"` | `"OPTIONS"`, [`PublicHttpAction`](/api/modules/server#publichttpaction)]\[]

Returns a list of routed HTTP actions.

These are used to populate the list of routes shown in the Functions page of the Bijection dashboard.

#### Returns

readonly \[`string`, `"GET"` | `"POST"` | `"PUT"` | `"PATCH"` | `"DELETE"` | `"OPTIONS"`, [`PublicHttpAction`](/api/modules/server#publichttpaction)]\[]

* an array of \[path, method, endpoint] tuples.

***

### lookup

▸ **lookup**(`path`, `method`): `null` | readonly \[[`PublicHttpAction`](/api/modules/server#publichttpaction), `"GET"` | `"POST"` | `"PUT"` | `"PATCH"` | `"DELETE"` | `"OPTIONS"`, `string`]

Returns the appropriate HTTP action and its routed request path and method.

The path and method returned are used for logging and metrics, and should
match up with one of the routes returned by `getRoutes`.

For example,

```js theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
http.route({ pathPrefix: "/profile/", method: "GET", handler: getProfile});

http.lookup("/profile/abc", "GET") // returns [getProfile, "GET", "/profile/*"]
```

#### Parameters

| Name | Type |
| :- | :- |
| `path` | `string` |
| `method` | `"GET"` \| `"HEAD"` \| `"POST"` \| `"PUT"` \| `"PATCH"` \| `"DELETE"` \| `"OPTIONS"` |

#### Returns

`null` | readonly \[[`PublicHttpAction`](/api/modules/server#publichttpaction), `"GET"` | `"POST"` | `"PUT"` | `"PATCH"` | `"DELETE"` | `"OPTIONS"`, `string`]

* a tuple \[[PublicHttpAction](/api/modules/server#publichttpaction), method, path] or null.

***

### runRequest

▸ **runRequest**(`argsStr`, `requestRoute`): `Promise`\<`string`>

Given a JSON string representation of a Request object, return a Response
by routing the request and running the appropriate endpoint or returning
a 404 Response.

#### Parameters

| Name | Type | Description |
| :- | :- | :- |
| `argsStr` | `string` | a JSON string representing a Request object. |
| `requestRoute` | `string` | - |

#### Returns

`Promise`\<`string`>

* a Response object.
