Expand description
Fusion Stack for Laravel for Rust: the same API format as the fusion-stack/laravel PHP
package, so @fusion-stack/client works unchanged against either backend.
Register FusionStack as a service provider, which renders every error as a JSON:API error
document, and attach it as middleware to your API routes:
use fusion_stack::{Config, FusionStack};
use fusion_stack::versioning::Versions;
use laravel::prelude::*;
let api = FusionStack::new(Config::new().versions(Versions::new("2026-11-30")));
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("/orders", index);
});
});
});Re-exports§
pub use crate::auth::RequiresScope;pub use crate::response_cache::CacheResponse;
Modules§
- auth
- API clients and scopes, as the PHP package’s
ResolveClientandAuthorizeScopesmiddleware andApiKeymodel provide them. - console
- The PHP package’s artisan commands, as Laravel for Rust console commands.
FusionStackregisters them, solaravel api:version:listand the rest work in any application that adds it as a service provider. - docs
- The API reference and changelog pages, as the PHP package’s
DocsControllerserves them atapi.docs.path: Scalar (or Redoc) over the OpenAPI document of each offered version, and the changelog rendered from each version’s changes. - errors
- Error codes, the
ApiErrorhandlers return, and the JSON:API error documents every error response becomes. - idempotency
- Idempotency keys, as the PHP package’s
Idempotencymiddleware handles them: a POST, PATCH or DELETE with anIdempotency-Keyruns once, and retries with the same key get the stored response withIdempotent-Replayed: true. A retry must be the same request (the same version, query and body), or it gets a 422idempotency_key_mismatch. While the first request runs, retries get a 409idempotency_in_progress. - openapi
- The OpenAPI 3.1 document, as the PHP package’s
Generatorwrites it, for each version. - rate_
limit - Rate limits per client, as the PHP package’s
RateLimitmiddleware sets them: each client’s tier allows a number of requests per window (guests use theguesttier, by IP address), and responses carryRateLimit-Limit,RateLimit-RemainingandRateLimit-Reset. Over the limit, a request gets a 429rate_limitedwithRetry-After. - request_
id X-Request-Id: a valid incoming ID is kept, otherwise the request gets areq_ID. Error documents repeat it inmeta.request_id.- resources
- JSON:API resource types: which table holds them, their attributes and relationships, and the
descriptions the OpenAPI document shows. [
crate::query::ApiQuery] reads and renders them. - response_
cache - The response cache, as the PHP package’s
ResponseCachemiddleware and#[CacheResponse]attribute do it: a route opts in, its successful GET responses are kept in a Laravel cache store, and later requests are answered from the store withX-Response-Cache: hit. Entries are tagged, andflushdrops every entry with any of the tags it is given. - testing
- Test helpers, as the PHP package’s
InteractsWithApi,ApiTestResponseandTransformsVersionChanges: request headers for versions, keys and idempotency, assertions for JSON:API documents, errors, replays, deprecation and shapes, and helpers that run one version change on its own. - versioning
- Date-based API versions: resolving the
Api-Versionheader, deprecation and retirement, and the version changes that let older clients keep the shape they were built against. - webhooks
- Webhooks, as the PHP package sends them: endpoints subscribe to event types (with patterns such
as
order.*) and are pinned to a version, events are recorded as one delivery per subscribed endpoint, and a queued job posts each delivery, signed with the endpoint’s secret, in the endpoint’s version. Failed deliveries are retried after the configured delays, and an endpoint whose deliveries fail too many times in a row is disabled.
Structs§
- Cache
Control - Route middleware that sets a route’s
Cache-Controlfor its successful GET responses, in place ofConfig::cache_control, ascache-control:route middleware does in PHP: - Config
- Fusion Stack’s settings, mirroring
config/api.phpin the PHP package. - Fusion
Stack - Fusion Stack: a service provider that renders errors, and the middleware for API routes. Cloning it is cheap, and every clone shares the same configuration.