#etag #static #static-file #axum #embed #serve-static #local-file

axum-embed-files

Developer-friendly zero-overhead static file handling for axum

1 unstable release

0.1.0-beta.0 Jan 11, 2024

#1228 in Filesystem

37 downloads per month

MIT license

10KB
104 lines

Serve static embedded files.

This crate provides utilities to serve static files that are embedded in the Rust binary at compile time. This is most useful for including small asset files directly in a web server. The files are served with Content-Type, ETag, and Last-Modified headers, and conditional requests are handled correctly (well, just If-None-Match so far).

For development, you may wish to serve the files directly from the local file system. Compile with the feature serve-from-fs and get coding!

Example

use axum::Router;
use axum_embed_files::embed_files;

fn router<S: Clone + Sync + Send + 'static>() -> Router<S> {
    embed_files!("assets", [
        "img/logo.svg",
        "style.css",
    ])
}

Dependencies

~4.5MB
~69K SLoC