Restify for Laravel for Rust

One definition.

A repository, written once in Rust.

Three interfaces.

An HTTP API, an OpenAPI document, and MCP tools for AI agents.

One rule guards all three.

A person or an AI agent: refused at the same line.

Build a new backend.

Three commands, then one file per model.

  1. Create a Laravel for Rust app

    laravel new my-api --rust
  2. Add Restify

    cargo add laravel-restify

    Then register it in src/app.rs, inside .with_providers(..): providers.add(restify::Restify::new());. Its commands come with it.

  3. Brief your AI coding agent

    laravel restify:install

    It writes two skills into .agents/skills and .claude/skills, and lists them in AGENTS.md. An agent working in the app then knows how a repository is written, and where the guides for your version are.

One file per model.

What clients may send, what a response shows, what is related, and who may do what.

#[laravel::input(fills = Comment)]
#[validate(authenticated)]
#[derive(Schema)]
pub struct NewComment {
    #[validate(required, exists(Post::id))]
    pub post_id: i64,
    #[validate(required, min_length(2))]
    pub body: String,
}

impl Repository for CommentRepository {
    type Model = Comment;
    type Store = NewComment;
    type Update = EditComment;

    fn fields() -> Vec<Field<Comment>> {
        vec![
            Field::new(Comment::post_id).matchable(),
            Field::new(Comment::body).searchable(),
            Field::new(Comment::created_at),
        ]
    }

    const MCP: Option<McpTools> = Some(McpTools::INDEX.show(true));

    fn related() -> Vec<Related<Comment>> {
        vec![
            Related::through::<UserRepository>(Comment::user, |comment| &comment.user),
            Related::raw(Comment::post),
        ]
    }

    async fn authorize(action: Action, request: &Request, comment: Option<&Comment>) -> laravel::Result<()> {
        match (action, comment) {
            (Action::AllowRestify | Action::Index | Action::Store, _) => Ok(()),
            (Action::Show, Some(comment)) => request.authorize(CommentPolicy::show, comment).await,
            (Action::Update, Some(comment)) => request.authorize(CommentPolicy::update, comment).await,
            (Action::Delete, Some(comment)) => request.authorize(CommentPolicy::delete, comment).await,
            _ => Err(laravel::abort(403)),
        }
    }
}

The whole API, served.

No controllers and no routes to write. Register the repository, and it answers.

impl Repository for CommentRepository

HTTP JSON:API

  • GET /api/restify/comments Lists a page: ?search= ?post_id= ?related=user,post ?page= ?perPage=
  • GET /api/restify/comments/{id} Shows one
  • POST /api/restify/comments Creates one
  • PUT /api/restify/comments/{id} Changes one, checking every field’s rules
  • PATCH /api/restify/comments/{id} Changes the fields it sends
  • DELETE /api/restify/comments/{id} Deletes one

OpenAPI 3.1

  • laravel restify:openapi The document of every endpoint, for API clients and SDK generators

MCP AI agents

  • comments-index-tool An agent lists comments
  • comments-show-tool An agent reads one, under the same authorize

Declare them, and the same file also serves bulk requests, actions and getters, nested routes and file uploads.

Move a PHP app.

Export it, import it, replay it until every answer matches.

  1. Describe and record the PHP app

    composer require --dev binarcode/laravel-restify-rust-migrate
    php artisan restify:rust-install

    Your AI coding agent can take it from there: type /restify-migrate in Claude Code. By hand, restify:export describes the app and restify:record saves what it really answers.

  2. Write the Rust app from it

    laravel restify:import ../php-app/restify-manifest.json

    Models, repositories, fields, filters and routes, in Rust. What is code in PHP, such as the body of a policy, becomes a numbered task in MIGRATION.md for your agent.

  3. Replay until it matches

    cargo test --test restify_parity

    It replays PHP’s recorded answers and names every difference. Green means the same API, on the same database, with the same tokens. The whole guide.

Recorded in PHP. Replayed in Rust.

41 recordings. 697 requests. The same answers, but for a short list of documented differences.

45 MiB

The whole server at its highest peak under load. A quarter of the code of the same endpoints written by hand, in the same memory.

Restify for Laravel for Rust

Open source, on crates.io.

Read it instead The guides GitHub llms.txt