# Crate Documentation **Version:** 1.1.0 **Format Version:** 45 # Module `web_service_files_axum` # Web service files axum **[documentation](https://docs.rs/web-service-files-axum/)** • **[source](https://github.com/joelparkerhenderson/web-service-files-axum/)** • **[llms.txt](https://raw.githubusercontent.com/joelparkerhenderson/web-service-files-axum/refs/heads/main/llms.txt)** • **[crate](https://crates.io/crates/web-service-files-axum)** • **[email](mailto:joel@joelparkerhenderson.com)** Web service that serves files using Axum, Tokio, Rust. This is a very simple web service that we use for testing our systems. ## Steps Run the service using the default address 0.0.0.0:8080: ```sh cargo run ``` You can browse files by name… Browse Browse Browse You should see a response that shows the file contents. ## Options Run the service using an environment variable for a custom bind address: ```sh export BIND="1.1.1.1:1111" cargo run ``` Run the service using environment variables for a custom host and port: ```sh export HOST="1.1.1.1" export PORT="1111" cargo run ``` ## References Based on Demo Rust Axum free open source software: ## Modules ## Module `app` ```rust pub(crate) mod app { /* ... */ } ``` ### Functions #### Function `app` Create our application by creating our router. ```rust pub fn app() -> axum::Router { /* ... */ } ``` ## Module `conf` Configuration module for the application. ```rust pub(crate) mod conf { /* ... */ } ``` ### Functions #### Function `bind_string` **Attributes:** - `#[allow(dead_code)]` Get the bind string from the environment variable BIND, or return the default bind address string "0.0.0.0:8080". ```rust pub async fn bind_string() -> String { /* ... */ } ``` #### Function `host_string` Get the host string from the environment variable HOST, or return the default host IP address string "0.0.0.0". ```rust pub async fn host_string() -> String { /* ... */ } ``` #### Function `port_string` Get the port string from the environment variable PORT, or return the default port number string "8080". ```rust pub async fn port_string() -> String { /* ... */ } ``` #### Function `shutdown_signal` Shutdown signal to run axum with graceful shutdown when a user presses Ctrl+C or Unix sends a terminate signal. ```rust pub async fn shutdown_signal() { /* ... */ } ``` ## Functions ### Function `main` The main function does these steps: - Start tracing and emit a tracing event. - Get a command line argument as our bind address. - Create our application which is an axum router. - Run our application as a hyper server. ```rust pub(crate) fn main() { /* ... */ } ```