fusion-stack-laravel-rust
Fusion Stack for Laravel for Rust: date-based API versioning, deprecation headers, request IDs and one JSON:API error format. It sends exactly what the fusion-stack/laravel PHP package sends, so @fusion-stack/client, @fusion-stack/nuxt and the docs work unchanged against either backend.
Developed in
fusion-stack/framework. Open issues and pull requests there.
The library is named fusion_stack. It needs Rust 1.99 or newer and laravel-rust 0.1.2 or a later 0.1 release.
Setup
Register FusionStack as a service provider, which renders every error as a JSON:API error document, and add it as middleware on your API routes:
use Arc;
use ;
use ;
use *;
let api = new;
configure
.with_providers
.with_routing;
Errors
Every error is sent as application/vnd.api+json with a stable code and the request ID in meta.request_id. Return an ApiError from a handler with into_error():
use ;
return Err;
Validation errors from the framework's Validate derive become validation_failed errors with a source.pointer for each field. Implement ErrorCode for your own codes.
Versioning
Clients send Api-Version: YYYY-MM-DD. Handlers always see the latest shape: each VersionChange upgrades older requests and downgrades responses for older versions. Changes can also add, remove or retire routes, or keep a frozen handler for older versions with legacy().
use ;
use ;
;
Unknown versions get a 400 invalid_api_version, retired ones a 410 api_version_retired, and deprecated ones the Deprecation, Sunset and Link headers.
Not yet in this crate
Query parameters, idempotency, the response cache, API keys and scopes, rate limit tiers, version usage tracking, webhooks, the OpenAPI document and the console commands are in the PHP package and planned here.
License
MIT.