Web Programming

cat-web-programming

Create applications for the Web.

The following table outlines common web development tasks and relevant Rust crates. The Rust web ecosystem offers a variety of options, from low-level networking to high-level frameworks.

TopicRust CratesNotes
Web Frameworks (Full-Stack)axum, actix-web, rocket, warpThese frameworks provide tools for building web applications, including routing, middleware, templating, and more. actix-web is known for its performance. axum is built on top of tower and hyper. rocket uses a more declarative approach. warp is a more lightweight framework.
Front-end Frameworks (WASM)yew, leptos, seed, dominatorThese frameworks enable building interactive web UIs with Rust compiled to WebAssembly (WASM). They provide component-based architectures and other tools for structuring front-end applications.
HTTP ServersCovered by web frameworks.Web frameworks typically handle HTTP server functionality.
REST API DesignOften uses web frameworks and serialization crates like serde.REST APIs are typically built using web frameworks and serialization crates.
HTTP Clientsreqwest, isahcThese crates provide HTTP client functionality for making requests to external services.
RoutingCovered by web frameworks.Web frameworks provide routing mechanisms to map requests to handlers.
MiddlewareOften provided by web frameworks or through crates like tower.Middleware allows you to add functionality to the request/response pipeline.
Templatingminijinja, tera, handlebars, askamaTemplating engines are used to generate HTML dynamically.
Web Authentication & Authorizationactix-web-httpauth (for Actix Web), tower-http (generic middleware)Authentication and authorization are often handled through middleware or dedicated crates.
WebSocketstokio-tungstenite, async-tungsteniteThese crates provide WebSocket support.
GraphQLasync-graphql, juniperThese crates enable building GraphQL APIs.
Static Site Generation (SSG)perseus (based on sycamore), zolaThese tools generate static websites from templates and content.

Choosing the Right Crates

Code Examples

HTTP Types & Interfaces

RecipeCratesCategories
httphttpcat-web-programming
http-body[![http-body][c-http-body-badge]][c-http-body]cat-web-programming
http-body-util[![http-body-util][c-http-body-util-badge]][c-http-body-util]cat-web-programming

Manipulate Uniform Resource Locations (URLs)

Handle Media Types (MIME)

Web Page Scraping

HTTP Clients

See Web Programming: HTTP Client.

HTTP Servers

See Web Programming: HTTP Server.

Web Authentication & Authorization

See Authentication.

GraphQL

See GraphQL.

WebSockets

See Web Programming: Websocket.

TopicRust Crates (Examples)Notes
Asynchronous Programming (Essential for Web)tokio, async-stdThese are asynchronous runtimes that are fundamental for writing efficient and scalable web applications in Rust.
Databasessqlx, diesel, mongodb (drivers)These crates provide database access for various database systems.
Networking (Low-Level)tokio::net, std::netThese modules provide low-level networking primitives. Often used by higher-level frameworks.
Serialization/Deserialization (JSON, etc.)serde, serde_json, serde_ymlserde is a powerful framework for serializing and deserializing data, often used with JSON and other formats.
TestingBuilt-in testing framework, reqwest for integration testingRust has a built-in testing framework, and reqwest can be used for integration testing of web services.

References