Skip to main content

Crate fusion_stack

Crate fusion_stack 

Source
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 ResolveClient and AuthorizeScopes middleware and ApiKey model provide them.
console
The PHP package’s artisan commands, as Laravel for Rust console commands. FusionStack registers them, so laravel api:version:list and 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 DocsController serves them at api.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 ApiError handlers return, and the JSON:API error documents every error response becomes.
idempotency
Idempotency keys, as the PHP package’s Idempotency middleware handles them: a POST, PATCH or DELETE with an Idempotency-Key runs once, and retries with the same key get the stored response with Idempotent-Replayed: true. A retry must be the same request (the same version, query and body), or it gets a 422 idempotency_key_mismatch. While the first request runs, retries get a 409 idempotency_in_progress.
openapi
The OpenAPI 3.1 document, as the PHP package’s Generator writes it, for each version.
rate_limit
Rate limits per client, as the PHP package’s RateLimit middleware sets them: each client’s tier allows a number of requests per window (guests use the guest tier, by IP address), and responses carry RateLimit-Limit, RateLimit-Remaining and RateLimit-Reset. Over the limit, a request gets a 429 rate_limited with Retry-After.
request_id
X-Request-Id: a valid incoming ID is kept, otherwise the request gets a req_ ID. Error documents repeat it in meta.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 ResponseCache middleware 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 with X-Response-Cache: hit. Entries are tagged, and flush drops every entry with any of the tags it is given.
testing
Test helpers, as the PHP package’s InteractsWithApi, ApiTestResponse and TransformsVersionChanges: 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-Version header, 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§

CacheControl
Route middleware that sets a route’s Cache-Control for its successful GET responses, in place of Config::cache_control, as cache-control: route middleware does in PHP:
Config
Fusion Stack’s settings, mirroring config/api.php in the PHP package.
FusionStack
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.