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.
Topic | Rust Crates | Notes |
---|---|---|
Web Frameworks (Full-Stack) | axum ⮳, actix-web ⮳, rocket ⮳, warp ⮳ | These 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 ⮳, dominator ⮳ | These 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 Servers | Covered by web frameworks. | Web frameworks typically handle HTTP server functionality. |
REST API Design | Often uses web frameworks and serialization crates like serde ⮳. | REST APIs are typically built using web frameworks and serialization crates. |
HTTP Clients | reqwest ⮳, isahc ⮳ | These crates provide HTTP client functionality for making requests to external services. |
Routing | Covered by web frameworks. | Web frameworks provide routing mechanisms to map requests to handlers. |
Middleware | Often provided by web frameworks or through crates like tower ⮳. | Middleware allows you to add functionality to the request/response pipeline. |
Templating | minijinja ⮳, tera ⮳, handlebars ⮳, askama ⮳ | Templating engines are used to generate HTML dynamically. |
Web Authentication & Authorization | actix-web-httpauth ⮳ (for Actix Web), tower-http ⮳ (generic middleware) | Authentication and authorization are often handled through middleware or dedicated crates. |
WebSockets | tokio-tungstenite ⮳, async-tungstenite ⮳ | These crates provide WebSocket support. |
GraphQL | async-graphql ⮳, juniper ⮳ | These crates enable building GraphQL APIs. |
Static Site Generation (SSG) | perseus ⮳ (based on sycamore ), zola ⮳ | These tools generate static websites from templates and content. |
Choosing the Right Crates
- Full-Stack Web App:
axum
⮳,actix-web
⮳,rocket
⮳,warp
⮳. - Front-end Web App (WASM):
yew
⮳,seed
⮳,leptos
⮳. - REST API: Web framework +
serde
⮳. - GraphQL API:
async-graphql
⮳. - Static Site Generation:
perseus
⮳,zola
⮳.
Code Examples
HTTP Types & Interfaces
Recipe | Crates | Categories |
---|---|---|
http | ||
http-body | [![http-body][c-http-body-badge]][c-http-body] | |
http-body-util | [![http-body-util][c-http-body-util-badge]][c-http-body-util] |
FIXME
Manipulate Uniform Resource Locations (URLs)
Handle Media Types (MIME)
Recipe | Crates | Categories |
---|---|---|
Get a MIME Type from a String | ||
Get a MIME Type from a Filename | ||
Parse the MIME Type of a HTTP Response |
Web Page Scraping
Recipe | Crates | Categories |
---|---|---|
Extract all Links from the HTML of a Webpage | ||
Check a Webpage for Broken Links | ||
Extract all Unique Links from a MediaWiki Markup |
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.
Related Topics
Topic | Rust Crates (Examples) | Notes |
---|---|---|
Asynchronous Programming (Essential for Web) | tokio ⮳, async-std ⮳ | These are asynchronous runtimes that are fundamental for writing efficient and scalable web applications in Rust. |
Databases | sqlx ⮳, diesel ⮳, mongodb ⮳ (drivers) | These crates provide database access for various database systems. |
Networking (Low-Level) | tokio::net , std::net | These modules provide low-level networking primitives. Often used by higher-level frameworks. |
Serialization/Deserialization (JSON, etc.) | serde ⮳, serde_json ⮳, serde_yml ⮳ | serde ⮳ is a powerful framework for serializing and deserializing data, often used with JSON and other formats. |
Testing | Built-in testing framework, reqwest ⮳ for integration testing | Rust has a built-in testing framework, and reqwest ⮳ can be used for integration testing of web services. |