Quickstart: Laravel for Rust
Fusion Stack runs on Laravel for Rust as well as on Laravel. The crate, fusion-stack-laravel-rust, sends exactly what the PHP package sends: the same error documents, headers, versions, queries and OpenAPI document. @fusion-stack/client, @fusion-stack/nuxt and everything else that talks HTTP work unchanged against either backend, and both packages pass the same HTTP conformance cases on every change.
You need Rust 1.99 or newer and a Laravel for Rust app (laravel-rust 0.1.2 or a later 0.1 release). To create one, follow the framework's installation guide.
Install the crate
cargo add fusion-stack-laravel-rust --features databaseThe library is named fusion_stack. The database feature adds queries, API keys, version usage, webhooks and their migrations and commands; leave it out for errors, request IDs, versioning and caching only.
What it covers
Everything the PHP package does, except the MCP server and the starter kit, which are PHP only.
| Feature | Laravel (PHP) | Laravel for Rust |
|---|---|---|
| Error format and error codes | ✓ | ✓ |
| Request IDs | ✓ | ✓ |
| Date-based versioning, deprecation, sunsets and brownouts | ✓ | ✓ |
| JSON:API queries: include, fields, filter, sort, page | ✓ | ✓ |
| Idempotency | ✓ | ✓ |
| Caching and the response cache | ✓ | ✓ |
| API keys and scopes | ✓ | ✓ |
| Rate limit tiers and headers | ✓ | ✓ |
| Webhooks | ✓ | ✓ |
| OpenAPI and the API reference | ✓ | ✓ |
| Console commands | ✓ | ✓ |
| Testing helpers | ✓ | ✓ |
Set up the API
FusionStack is both a service provider and middleware. The provider renders every error as a JSON:API error document and registers the migrations and api: commands; the middleware adds request IDs, authentication, rate limits, versioning, idempotency and HTTP caching to the routes it wraps. A Resource says how a table is rendered, and an ApiQuery what clients may ask for:
use fusion_stack::query::ApiQuery;
use fusion_stack::resources::{Kind, Resource};
use fusion_stack::{Config, FusionStack};
use laravel::prelude::*;
fn customers() -> ApiQuery {
ApiQuery::new("customers")
.filter("email", ["eq"])
.sorts(["full_name", "created_at"])
}
async fn index(request: Request) -> laravel::Result<Response> {
customers().paginate(&request).await
}
let api = FusionStack::new(
Config::new().resource(
Resource::new("customers", "customers")
.attribute("full_name", Kind::String)
.attribute("email", Kind::String)
.attribute("created_at", Kind::Timestamp),
),
);
Application::configure()
.with_providers({
let api = api.clone();
move |providers| {
providers.add(api);
}
})
.with_routing(move |routing, _| {
let api = api.clone();
routing.api(move |route| {
route.prefix("/v1").middleware(api).group(|route| {
route.get("/customers", index);
});
});
});Make a request
Run the migrations, create an API key and ask for the customers. Laravel for Rust serves API routes under /api; call routing.api_prefix("") to serve them at /v1 as the PHP starter kit does.
laravel migrate
laravel api:key:create "Local"
export KEY=fs_live_…
laravel serve
curl "localhost:8000/api/v1/customers?sort=-created_at" -H "Authorization: Bearer $KEY"The response is the same JSON:API document, with the same links, meta.page and headers, that the PHP package sends for the same data. /v1/customers?sort=colour is a 400 invalid_sort, worded as in PHP.
The Laravel for Rust reference covers every part of the crate. The rest of this page goes further into configuration, errors and versioning.
Configuration
Config mirrors config/api.php, one builder method per key; the configuration reference lists them all. For example:
| Method | PHP config key | Default |
|---|---|---|
request_ids(bool) | api.request_id.enabled | true |
error_paths([...]) | api.errors.paths | ["*"]: every path |
versions(Versions) | api.versions | Versioning off |
rate_limit_tier(name, Tier) | api.rate_limit.tiers | guest 60, default 300 a minute |
Versions has the same settings as api.versions: default_version, version (one per release, with its changes), retired, keep, deprecated, changelog_url and upgrade_guide_url.
Errors
Return an ApiError with into_error(). The builder methods match the PHP ApiException:
use fusion_stack::errors::{ApiError, ApiErrorCode};
async fn cancel(request: Request) -> laravel::Result<Response> {
// ...
Err(ApiError::new(ApiErrorCode::Conflict, "Only pending and paid orders can be cancelled.")
.pointer("/data/attributes/status")
.meta("status", "shipped")
.into_error())
}{
"errors": [
{
"status": "409",
"code": "conflict",
"title": "Conflict",
"detail": "Only pending and paid orders can be cancelled.",
"source": { "pointer": "/data/attributes/status" },
"meta": { "status": "shipped", "request_id": "req_01m8rqk3gyc6efkra6dzkkyf61" }
}
]
}ApiErrorCode has every code in the error code reference, with the same statuses and titles. For your own codes, implement the ErrorCode trait on an enum. The framework's own errors are converted too: validation failures from the Validate derive become validation_failed with a pointer per field, unknown routes not_found, wrong methods method_not_allowed, and, with the database feature, a missing model not_found without naming the model.
Use ? with into_error(): ApiError has no From conversion, because the framework already converts every error type into its own.
Versioning
Version changes work as in PHP: handlers only ever see the latest shape, and each change upgrades older requests and downgrades responses for clients on older versions. A change is a type implementing VersionChange:
use fusion_stack::versioning::{VersionChange, document};
use serde_json::{Map, Value};
pub struct RenameCustomerNameToFullName;
impl VersionChange for RenameCustomerNameToFullName {
fn description(&self) -> &str {
"customer.name renamed to customer.full_name"
}
fn resources(&self) -> &[&'static str] {
&["customers"]
}
fn transform_request(&self, payload: &mut Map<String, Value>) {
let mut body = Value::Object(std::mem::take(payload));
document::rename_attribute(&mut body, self.resources(), "name", "full_name");
if let Value::Object(map) = body {
*payload = map;
}
}
fn transform_response(&self, document: &mut Value) {
document::rename_attribute(document, self.resources(), "full_name", "name");
}
}PHP names routes by their Laravel route name; Laravel for Rust routes have no names, so here a route is named by its method and URI pattern, such as GET /v1/orders/{order}/summary, and * matches anything. Besides the transforms, a change can declare:
| Method | Effect on older versions | PHP equivalent |
|---|---|---|
added_routes() | 404 | $addedRoutes |
removed_routes() | Still served; this version and newer get 404 | $removedRoutes |
unavailable_to_older_versions() | 410 endpoint_unavailable_for_version | $unavailableToOlderVersions |
legacy_handlers() | Served by a frozen handler, wrapped with legacy() | $legacyControllers |
The document module has the helpers types, map_attributes, rename_key, rename_attribute, remove_attribute and add_attribute.
Deprecation and retirement
use fusion_stack::versioning::{Deprecated, Versions};
Versions::new("2026-11-30")
.version("2026-06-01", vec![])
.version("2026-11-30", vec![/* ... */])
.deprecated(
"2026-06-01",
Deprecated::new()
.sunset("2027-06-01")
.brownout("2027-05-04 14:00", "2027-05-04 15:00"),
)
.retired("2025-01-01")
.changelog_url("https://example.com/changelog")
.upgrade_guide_url("https://example.com/upgrade");Deprecated versions get the Deprecation, Sunset and Link headers. During a brownout they get 410 api_version_brownout with Retry-After, and after the sunset or once retired, 410 api_version_retired. As in PHP, versions older than the newest two are deprecated automatically; change that with keep().
The playground
The monorepo's workbench/rust app serves the same Customers and Orders API as the PHP playground with this crate. See the contributing guide to run it.