ワンクリックで
mockaton
Generates and serves mock HTTP APIs. Use when creating, editing, or reasoning about mock endpoints.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Generates and serves mock HTTP APIs. Use when creating, editing, or reasoning about mock endpoints.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
| name | Mockaton |
| description | Generates and serves mock HTTP APIs. Use when creating, editing, or reasoning about mock endpoints. |
| user-invocable | false |
Mockaton has no dependencies.
npm install -g mockaton
mockaton --port 2020 my-mocks-dir/
Mockaton will serve the files on the given directory. It's a file-system based router in which
filenames can have dynamic parameters and comments. For paraments use square brackets [],
and for comments use parentheses (). Comments are handy because this way each route
can have different mock file variants. Similarly, each route can have different response status
code variants.
| Route | Filename | Description |
|---|---|---|
| /api/company/123 | api/company/[id].GET.200.ts | [id] is a dynamic parameter. .ts, and .js are sent as JSON by default. |
| /media/avatar.png | media/avatar.png | Statics assets don't need the above extension. |
| /api/login | api/login(invalid attempt).POST.401.ts | Anything within parenthesis is a comment. They are ignored when routing. |
| /api/login | api/login(default).GET.200.ts | (default) is a special comment; otherwise, the first mock variant in alphabetical order wins. |
| /api/login | api/login(locked out user).POST.423.json | .json is allowed too. |
Write it to your mocks directory. .ts files are served as JSON by default.
mkdir -p my-mocks-dir/api
echo "export default { name: 'John' }" > my-mocks-dir/api/user.GET.200.ts
For JSON responses, use TypeScript (or JS), and export default an Object, Array, or
String.
interface Company {
name: string
}
export default {
name: 'Acme, Inc.'
} satisfies Company
<company>
<name>Acme, Inc.</name>
</company>
With a function mock you can do pretty much anything you could do with a normal backend handler. For example, you can handle complex logic, URL parsing, saving to a database, etc.
import { IncomingMessage, OutgoingMessage } from 'node:http'
import { parseSegments } from 'mockaton'
export default async function (req: IncomingMessage, response: OutgoingMessage) {
const { companyId, userId } = parseSegments(req.url, import.meta.filename)
const foo = await getFoo()
return JSON.stringify({
foo,
companyId,
userId,
name: 'Acme, Inc.'
})
}