# Restify for Laravel for Rust > A Rust crate, `laravel-restify` (imported as `restify`), for Laravel for Rust applications. You describe a model's API once, in a repository, and Restify serves JSON:API endpoints, MCP tools for AI agents and an OpenAPI 3.1 document from it, with the same authorization and validation for all of them. Made by BinarCode. Version 0.2, on `laravel-rust` 0.2. It is on crates.io, and its source is at https://github.com/BinarCode/laravel-restify-rust under the MIT licence. Key facts: - A repository refuses every request with `403` until its `authorize` method allows it. The messages are Restify for PHP's, such as `This action is unauthorized.` Clients can only write the fields of the input structs, and only search, filter and sort by the columns the repository lists. - A repository's `fields()` lists what a resource shows, as `Field::new(Post::title).searchable().sortable()`. A field is a typed column of the model, so a wrong column is a compile error and a wrong value is a `422`. A list searches, filters and sorts only by the fields marked for it and ignores every other parameter, as Restify for PHP does; the column never reaches the query. - Each repository named `posts` serves `GET/POST /api/restify/posts`, `GET/PUT/PATCH/DELETE /api/restify/posts/{id}`, and the MCP tools `posts-index`, `posts-show`, `posts-store`, `posts-update` and `posts-delete` at `POST /mcp/restify`. The tools run the same code as the endpoints. - The same repository produces an OpenAPI 3.1 document: `laravel restify:openapi`. - It is built to answer exactly as Restify for Laravel in PHP does, so a PHP application can move without its clients changing. The proof is a recording: 41 recordings of the real PHP package (697 requests: lists, filters, advanced filters and the filters listing, global search, grouping, sorting, pagination, relationships, attach, detach and sync, nested relationship routes, writes, validation, bulk, actions, getters, per-repository prefixes, public repositories and middleware, Sanctum tokens, register and login, the profile, soft deletes, file and image uploads) replay against the Rust version on SQLite, PostgreSQL, MySQL and MariaDB, with a short list of documented differences. The MCP tools match PHP’s too, by name and by answer, except that they don’t take files. `restify:import` converts a PHP application from its `restify:export` file, with a numbered task for each part that is code in PHP. - Measured against Restify for PHP on one migrated project-tracker application (the same SQLite data on the same disk, a token on every request, 10 connections; PHP on nginx and php-fpm with opcache): show one record 17,564 requests a second against 1,720 (10.2 times), list of 15 3,593 against 801 (4.5 times), list of 100 with related data 1,425 against 155 (9.2 times), create a record 3,384 against 1,837 (1.8 times), and 125 MiB of memory against 384. - Measured against the same endpoints written by hand on the same framework (Docker Desktop on a Mac): under load the whole server peaked at 31 to 45 MiB of memory in every test, the same as with the hand-written ones; showing or creating one record showed no measurable difference (smaller than the run-to-run noise). In the benchmark's source, the hand-written list, show and create take 135 lines; the Restify repository takes 33 and also serves update, delete, bulk and the MCP tools (both use the same 11-line input struct). There are no measurements against PHP or against other frameworks. - Install it with `cargo add laravel-restify` (crates.io, version 0.2). It needs a Laravel for Rust application on `laravel-rust` 0.2 and Rust 1.99 or later. Restify 0.1 is for `laravel-rust` 0.1. The Composer package a PHP application installs to migrate is `binarcode/laravel-restify-rust-migrate`, on Packagist. - For AI coding agents: `laravel restify:install` writes a skill to `.agents/skills/building-apis-with-restify` (and the same files to `.claude/skills`, for Claude Code's slash commands), and `laravel restify:list --json` lists what an application serves. ## Building a new backend 1. Create a Laravel for Rust application: `laravel new my-api --rust`. 2. Add the crate: `cargo add laravel-restify`. The package is `laravel-restify`; code imports it as `restify`. 3. Register the provider in `src/app.rs`, inside `.with_providers(..)`: `providers.add(restify::Restify::new());`. Restify's commands come with it. 4. Run `laravel restify:install`. It writes two skills into `.agents/skills` (`building-apis-with-restify` and `restify-migrate`), the same files into `.claude/skills` for Claude Code, and lists them in `AGENTS.md`, so an AI coding agent working in the application knows how a repository is written and where the guides for the installed version are. 5. Write one file per model, such as `src/models/comment.rs`: the input structs with their validation rules (`#[validate(required, min_length(2))]`), and a repository with `fields()` (what a response shows, and what clients may search, filter and sort by), `related()` (the relationships clients may load) and `authorize()` (who may do what). Register it with `Restify::new().repository::()`. 6. No controllers and no routes are written. That one file serves `GET /api/restify/comments` (a page, with `?search=`, `?post_id=`, `?related=user,post`, `?page=`, `?perPage=`), `GET`, `PUT`, `PATCH` and `DELETE /api/restify/comments/{id}`, `POST /api/restify/comments`, the OpenAPI 3.1 document of every endpoint (`laravel restify:openapi`), and, with `const MCP`, the MCP tools `comments-index-tool` and `comments-show-tool` under the same `authorize`. Declared in the same file, it also serves bulk requests, actions and getters, nested routes and file uploads. The repository above is the example application's `CommentRepository`; [Repositories](docs/repositories.md) lists everything a repository can declare. ## Moving from Restify for PHP 1. In the PHP application: `composer require --dev binarcode/laravel-restify-rust-migrate`, then `php artisan restify:rust-install`, which writes the `restify-migrate` skill into `.agents/skills` and `.claude/skills`. An AI coding agent can take it from there: tell it "migrate this application to Rust with the restify-migrate skill", or type `/restify-migrate` in Claude Code. By hand: `php artisan restify:export` describes the application and `php artisan restify:record` saves what it really answers. 2. In a new Laravel for Rust application next to it: `laravel restify:import ../php-app/restify-manifest.json` writes the models, repositories, fields, filters and routes, and `MIGRATION.md`, a numbered task for each part that is code in PHP. 3. `cargo test --test restify_parity` replays PHP's recorded answers and names every difference, until there is none. ## Guides - [Overview](docs/overview.md): the crate's README, with a complete example of a model, its inputs and its repository. - [Documentation index](docs/documentation.md): the list of guides. - [Installation](docs/installation.md): add Restify to an application and serve a first model. - [Repositories](docs/repositories.md): everything a repository can declare. - [Fields](docs/fields.md): what a resource shows, in which view and to whom, and how each type is written. - [Filtering](docs/filtering.md): search, filters, sorting and pagination of a list. - [Relationships](docs/relationships.md): loading a model's related models with `?related=`. - [Writing](docs/writing.md): the input that creates and updates a model, validation, and hooks. - [Files and images](docs/files.md): file uploads, where they are saved, how they are shown, and deleting them. - [Actions and getters](docs/actions.md): operations beyond list, show, create, update and delete, such as publishing a post. - [Authorization](docs/authorization.md): API tokens, and who may do what. - [Sanctum tokens](docs/sanctum.md): keep the Laravel Sanctum tokens of a PHP application working after it moves to Rust, and create new ones. - [Authentication](docs/authentication.md): the register, login, logout, password reset, email verification and profile endpoints of Restify for PHP. - [Soft deletes](docs/soft-deletes.md): hide deleted rows, and mark rows deleted instead of removing them. - [Bulk operations](docs/bulk.md): creating, updating and deleting many models in one request, all or nothing. - [MCP](docs/mcp.md): the tools AI agents get, and how to connect an agent. - [OpenAPI](docs/openapi.md): the OpenAPI 3.1 document of the endpoints, for API clients and SDK generators. - [Reference](docs/reference.md): every endpoint, parameter, response shape and status code. - [Testing](docs/testing.md): testing endpoints, tools and commands. - [Before you go to production](docs/production.md): the settings to check before the first deploy. - [Troubleshooting](docs/troubleshooting.md): compiler errors and unexpected responses, with their fixes. - [Migrating from Restify for PHP](docs/migrating-from-php.md): move a PHP Restify API to Rust, and prove it answers the same. ## Optional - [The site as one page to read](read.html): what the film on the home page says, in words, with examples, what was measured and the status. - [All guides in one file](llms-full.txt): every guide above, inlined as Markdown. - [The source on GitHub](https://github.com/BinarCode/laravel-restify-rust): the crate, the example application, the recordings of PHP and the benchmark. - [The crate on crates.io](https://crates.io/crates/laravel-restify): `laravel-restify`. - [Restify for Laravel in PHP](https://github.com/BinarCode/laravel-restify): the PHP package this follows. - Each guide is also an HTML page: replace `.md` with `.html`. - [Laravel for Rust](https://laravel.com/rust): the framework Restify runs on.