Expand description
Provides functions to easily integrate Leptos with Axum.
§JS Fetch Integration
The leptos_axum integration supports running in JavaScript-hosted WebAssembly
runtimes, e.g., running inside Deno, Cloudflare Workers, or other JS environments.
To run in this environment, you need to disable the default feature set and enable
the wasm feature on leptos_axum in your Cargo.toml.
leptos_axum = { version = "0.6.0", default-features = false, features = ["wasm"] }§Features
default: supports running in a typical native Tokio/Axum environmentwasm: withdefault-features = false, supports running in a JS Fetch-based environment
§Important Note
Prior to 0.5, using default-features = false on leptos_axum simply did nothing. Now, it actively
disables features necessary to support the normal native/Tokio runtime environment we create. This can
generate errors like the following, which don’t point to an obvious culprit:
spawn_localcalled from outside of atask::LocalSet
If you are not using the wasm feature, do not set default-features = false on this package.
§More information
For more details on how to use the integrations, see the
examples
directory in the Leptos repository.
Structs§
- Axum
Route Listing - A route that this application can serve.
- Response
Options - Allows you to override details of the HTTP response like the status code and add Headers/Cookies.
- Response
Parts - This struct lets you define headers and override the status of the Response from an Element or a Server Function Typically contained inside of a ResponseOptions. Setting this is useful for cookies and custom responses.
- Static
Route Generator - Allows generating any prerendered routes.
Traits§
- Leptos
Routes - This trait allows one to pass a list of routes and a render function to Axum’s router, letting us avoid having to use wildcards or manually define all routes in multiple places.
Functions§
- extract
- A helper to make it easier to use Axum extractors in server functions.
- extract_
with_ state - A helper to make it easier to use Axum extractors in server functions. This
function is compatible with extractors that require access to
State. - file_
and_ error_ handler - A reasonable handler for serving static files (like JS/WASM/CSS) and 404 errors.
- file_
and_ error_ handler_ with_ context - A reasonable handler for serving static files (like JS/WASM/CSS) and 404 errors.
- generate_
request_ and_ parts - Decomposes an HTTP request into its parts, allowing you to read its headers and other data without consuming the body. Creates a new Request from the original parts for further processing
- generate_
route_ list - Generates a list of all routes defined in Leptos’s Router in your app. We can then use this to automatically create routes in Axum’s Router without having to use wildcard matching or fallbacks. Takes in your root app Element as an argument so it can walk you app tree. This version is tailored to generate Axum compatible paths.
- generate_
route_ list_ with_ exclusions - Generates a list of all routes defined in Leptos’s Router in your app. We can then use this to automatically
create routes in Axum’s Router without having to use wildcard matching or fallbacks. Takes in your root app Element
as an argument so it can walk you app tree. This version is tailored to generate Axum compatible paths. Adding excluded_routes
to this function will stop
.leptos_routes()from generating a route for it, allowing a custom handler. These need to be in Axum path format - generate_
route_ list_ with_ exclusions_ and_ ssg - Generates a list of all routes defined in Leptos’s Router in your app. We can then use this to automatically
create routes in Axum’s Router without having to use wildcard matching or fallbacks. Takes in your root app Element
as an argument so it can walk you app tree. This version is tailored to generate Axum compatible paths. Adding excluded_routes
to this function will stop
.leptos_routes()from generating a route for it, allowing a custom handler. These need to be in Axum path format - generate_
route_ list_ with_ exclusions_ and_ ssg_ and_ context - Generates a list of all routes defined in Leptos’s Router in your app. We can then use this to automatically
create routes in Axum’s Router without having to use wildcard matching or fallbacks. Takes in your root app Element
as an argument so it can walk you app tree. This version is tailored to generate Axum compatible paths. Adding excluded_routes
to this function will stop
.leptos_routes()from generating a route for it, allowing a custom handler. These need to be in Axum path format Additional context will be provided to the app Element. - generate_
route_ list_ with_ ssg - Generates a list of all routes defined in Leptos’s Router in your app. We can then use this to automatically create routes in Axum’s Router without having to use wildcard matching or fallbacks. Takes in your root app Element as an argument so it can walk you app tree. This version is tailored to generate Axum compatible paths.
- handle_
response_ inner - Can be used in conjunction with a custom file_and_error_handler_with_context to process an Axum Request into an Axum Response
- handle_
server_ fns - An Axum handlers to listens for a request with Leptos server function arguments in the body,
run the server function if found, and return the resulting
Response. - handle_
server_ fns_ with_ context - An Axum handlers to listens for a request with Leptos server function arguments in the body,
run the server function if found, and return the resulting
Response. - redirect
- Provides an easy way to redirect the user from within a server function.
- render_
app_ async - Returns an Axum Handler that listens for a
GETrequest and tries to route it using leptos_router, asynchronously rendering an HTML page after allasyncresources have loaded. - render_
app_ async_ stream_ with_ context - Returns an Axum Handler that listens for a
GETrequest and tries to route it using leptos_router, asynchronously rendering an HTML page after allasyncresources have loaded. - render_
app_ async_ with_ context - Returns an Axum Handler that listens for a
GETrequest and tries to route it using leptos_router, asynchronously rendering an HTML page after allasyncresources have loaded. - render_
app_ to_ stream - Returns an Axum Handler that listens for a
GETrequest and tries to route it using leptos_router, serving an HTML stream of your application. - render_
app_ to_ stream_ in_ order - Returns an Axum Handler that listens for a
GETrequest and tries to route it using leptos_router, serving an in-order HTML stream of your application. This stream will pause at each<Suspense/>node and wait for it to resolve before sending down its HTML. The app will become interactive once it has fully loaded. - render_
app_ to_ stream_ in_ order_ with_ context - Returns an Axum Handler that listens for a
GETrequest and tries to route it using leptos_router, serving an in-order HTML stream of your application. This stream will pause at each<Suspense/>node and wait for it to resolve before sending down its HTML. The app will become interactive once it has fully loaded. - render_
app_ to_ stream_ with_ context - Returns an Axum Handler that listens for a
GETrequest and tries to route it using leptos_router, serving an HTML stream of your application. - render_
app_ to_ stream_ with_ context_ and_ replace_ blocks - Returns an Axum Handler that listens for a
GETrequest and tries to route it using leptos_router, serving an HTML stream of your application. - render_
route - Returns an Axum Handler that listens for a
GETrequest and tries to route it using leptos_router, serving an HTML stream of your application. The difference between calling this andrender_app_to_stream_with_context()is that this one respects theSsrModeon each Route and thus requiresVec<AxumRouteListing>for route checking. This is useful if you are using.leptos_routes_with_handler() - render_
route_ with_ context - Returns an Axum Handler that listens for a
GETrequest and tries to route it using leptos_router, serving an HTML stream of your application. It allows you to pass in a context function with additional info to be made available to the app The difference between calling this andrender_app_to_stream_with_context()is that this one respects theSsrModeon each Route, and thus requiresVec<AxumRouteListing>for route checking. This is useful if you are using.leptos_routes_with_handler().
Type Aliases§
- Pinned
Html Stream - A stream of bytes of HTML.