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

# Map local

> Serve local files instead of upstream responses

Map local lets you serve files from your machine instead of fetching them from the upstream server. Use it to test API responses, mock endpoints, or override assets without changing your backend.

Map local is implemented through the scripting system using `ctx.respondWith({file})`.

## Quick add via TUI

Press **S** to open the scripts manager, then **m** to add a Map Local rule. Enter a URL pattern and a local file path — httpmon generates a script that serves the file for matching requests.

| Key     | Action                                 |
| ------- | -------------------------------------- |
| `S`     | Open scripts manager                   |
| `m`     | Add a new Map Local rule               |
| `Tab`   | Switch between pattern and path fields |
| `Enter` | Save the rule                          |
| `Esc`   | Cancel                                 |

## Via scripts

Use `ctx.respondWith` with the `file` option in an `onRequest` hook.

```javascript theme={"theme":{"light":"github-light","dark":"github-dark"}}
// ---
// name: Mock Config Endpoint
// match:
//   - "*://api.example.com/config"
// enabled: true
// ---

function onRequest(ctx) {
  ctx.respondWith({ file: "config.json" });
}
```

The `file` path is relative to the script directory (`~/.httpmon/scripts/`). The content type is auto-detected from the file extension.

You can also return inline content:

```javascript theme={"theme":{"light":"github-light","dark":"github-dark"}}
function onRequest(ctx) {
  ctx.respondWith({
    status: 200,
    body: '{"mocked": true}',
    headers: { "Content-Type": "application/json" }
  });
}
```

See [scripting](/features/scripting) for the full script API.

## How it works

When a request matches a map local script, httpmon returns the local file's content directly to the client without contacting the upstream server. The `ctx.respondWith()` call in `onRequest` halts script execution immediately and sends the synthetic response.

Scripts that use `ctx.respondWith()` are tagged with a **Map Local** badge in the scripts manager so you can tell them apart from regular scripts.
