Laravel
Scramble reads your Laravel routes, form requests and API resources and builds an OpenAPI document without annotations. The HyperFetch CLI reads that document and writes a typed TypeScript SDK, so your frontend calls every route with your validation rules and resources as types.
- No annotations: Scramble infers the document from the code you already have.
- Validation rules as types: Form request rules become the payload type of each request.
- One command to resync: Change a route, regenerate, and the compiler shows every call to fix.
How it fits together
| Step | Where | What happens |
|---|---|---|
| 1 | Laravel | Scramble serves /docs/api.json built from your routes |
| 2 | Terminal | @hyper-fetch/cli generate reads it and writes src/api/laravel.sdk.ts |
| 3 | Frontend | createSdk(client) gives you typed requests for every route |
1. Serve the OpenAPI document
Install Scramble:
composer require dedoc/scramble
It documents the routes under api/ with no configuration:
Route::get('/users/{user}', fn (User $user) => new UserResource($user));
The document is on http://localhost:8000/docs/api.json. To write it to a file, run php artisan scramble:export.
/api prefixScramble lists the paths without the api/ prefix and puts it in the server URL instead. Give the HyperFetch client
the same base URL, ending with /api.
2. Generate the SDK
Run the CLI in your frontend project:
npx @hyper-fetch/cli@latest generate --template openapi --url http://localhost:8000/docs/api.json --fileName laravel.sdk.ts
It writes laravel.sdk.ts to src/api. On the first run it also creates api.json with that location. Every path becomes a key
and every method a $-prefixed key on it, so GET /users/{user} is sdk.users.$user.$get.
3. Call your API
import { createClient } from "@hyper-fetch/core";
import { createSdk } from "./api/laravel.sdk";
export const client = createClient({ url: "http://localhost:8000/api" });
export const sdk = createSdk(client);
import { sdk } from "./client";
// Typed from UserResource
const { data, error } = await sdk.users.$user.$get
.setParams({ user: 42 })
.send();
The same requests work with useFetch and useSubmit from @hyper-fetch/react, with caching, retries and deduplication included.
Keep the SDK in sync
Install the CLI in the frontend project and add a script, so regenerating is one command locally and in CI:
{
"scripts": {
"api:generate": "hyper-fetch generate -t openapi -u http://localhost:8000/docs/api.json -f laravel.sdk.ts -o"
}
}
-o overwrites the old file without asking. To generate without a running server, export the document with php artisan scramble:export and pass the file
to --url instead.
- Your backend is Laravel and your frontend is a TypeScript app.
- You want changes to form requests and resources to show up as TypeScript errors.
- You want caching, retries and React hooks on top of the generated client.
- Scramble builds an OpenAPI document from your Laravel routes.
@hyper-fetch/cli generateturns it into a typed SDK.createSdk(client)gives you typed requests forsend(),useFetchanduseSubmit.
