axum/README.md

85 lines
2.7 KiB
Markdown
Raw Normal View History

2021-07-09 21:36:14 +02:00
# axum
2021-05-31 16:28:26 +02:00
2021-07-09 21:36:55 +02:00
axum is a web application framework that focuses on ergonomics and modularity.
2021-05-31 16:28:26 +02:00
2021-07-09 21:36:14 +02:00
[![Build status](https://github.com/davidpdrsn/axum/workflows/CI/badge.svg)](https://github.com/davidpdrsn/axum/actions)
2021-06-12 20:18:21 +02:00
<!--
2021-07-09 21:36:14 +02:00
[![Crates.io](https://img.shields.io/crates/v/axum)](https://crates.io/crates/axum)
[![Documentation](https://docs.rs/axum/badge.svg)](https://docs.rs/axum)
[![Crates.io](https://img.shields.io/crates/l/axum)](LICENSE)
2021-06-12 20:18:21 +02:00
-->
More information about this crate can be found in the [crate documentation][docs].
## Goals
2021-05-31 16:28:26 +02:00
2021-06-06 20:39:54 +02:00
- Ease of use. Building web apps in Rust should be as easy as `async fn
2021-06-06 15:20:27 +02:00
handle(Request) -> Response`.
2021-07-09 21:42:41 +02:00
- Solid foundation. axum is built on top of [tower] and [hyper] and makes it
2021-07-09 23:39:39 +02:00
easy to plug in any middleware from the [tower] and [tower-http] ecosystem.
2021-07-22 15:44:16 +02:00
This improves modularity since axum doesn't have its own custom
middleware system.
- Focus on routing, extracting data from requests, and building responses.
2021-07-09 21:42:41 +02:00
tower middleware can handle the rest.
2021-07-09 21:36:14 +02:00
- Macro free core. Macro frameworks have their place but axum focuses
2021-06-06 15:20:27 +02:00
on providing a core that is macro free.
2021-05-31 16:28:26 +02:00
2021-06-12 20:18:21 +02:00
## Usage example
2021-05-31 16:28:26 +02:00
2021-06-06 15:20:27 +02:00
```rust
2021-07-09 21:36:14 +02:00
use axum::prelude::*;
2021-06-06 15:20:27 +02:00
use hyper::Server;
use std::net::SocketAddr;
2021-06-01 00:47:12 +02:00
2021-06-06 15:20:27 +02:00
#[tokio::main]
async fn main() {
// build our application with a single route
2021-06-09 09:03:09 +02:00
let app = route("/", get(|| async { "Hello, World!" }));
2021-05-31 16:28:26 +02:00
2021-06-06 15:20:27 +02:00
// run it with hyper on localhost:3000
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
2021-06-08 21:21:20 +02:00
Server::bind(&addr)
2021-06-13 13:09:24 +02:00
.serve(app.into_make_service())
2021-06-08 21:21:20 +02:00
.await
.unwrap();
2021-06-06 15:20:27 +02:00
}
2021-05-31 16:28:26 +02:00
```
2021-06-13 13:09:24 +02:00
See the [crate documentation][docs] for way more examples.
2021-06-12 20:18:21 +02:00
## Examples
2021-06-09 09:03:09 +02:00
2021-07-09 21:36:14 +02:00
The [examples] folder contains various examples of how to use axum. The
2021-06-12 20:18:21 +02:00
[docs] also have lots of examples
2021-05-31 16:28:26 +02:00
2021-06-12 20:18:21 +02:00
## Getting Help
2021-06-06 15:20:27 +02:00
2021-07-09 21:36:14 +02:00
In the axum's repo we also have a [number of examples][examples]
2021-06-13 11:22:02 +02:00
showing how to put everything together. You're also welcome to ask in the
[`#tower` Discord channel][chat] or open an [issue] with your question.
2021-06-08 21:21:20 +02:00
2021-06-12 20:18:21 +02:00
## Contributing
2021-05-31 16:28:26 +02:00
2021-06-12 20:18:21 +02:00
:balloon: Thanks for your help improving the project! We are so happy to have
you! We have a [contributing guide][guide] to help you get involved in the
2021-07-09 21:36:14 +02:00
axum project.
2021-06-06 15:20:27 +02:00
2021-06-12 20:18:21 +02:00
## License
2021-06-06 15:20:27 +02:00
2021-06-12 20:18:21 +02:00
This project is licensed under the [MIT license](LICENSE).
2021-05-31 16:28:26 +02:00
2021-06-12 20:18:21 +02:00
### Contribution
2021-06-06 15:20:27 +02:00
2021-06-12 20:18:21 +02:00
Unless you explicitly state otherwise, any contribution intentionally submitted
2021-07-09 21:36:14 +02:00
for inclusion in axum by you, shall be licensed as MIT, without any
2021-06-12 20:18:21 +02:00
additional terms or conditions.
2021-06-07 16:31:11 +02:00
2021-07-09 21:36:14 +02:00
[examples]: https://github.com/davidpdrsn/axum/tree/master/examples
[docs]: https://docs.rs/axum/0.1.0
2021-06-06 15:20:27 +02:00
[tower]: https://crates.io/crates/tower
2021-07-09 21:42:41 +02:00
[hyper]: https://crates.io/crates/hyper
2021-06-06 15:20:27 +02:00
[tower-http]: https://crates.io/crates/tower-http
2021-06-12 20:18:21 +02:00
[guide]: CONTRIBUTING.md
[chat]: https://discord.gg/tokio
2021-07-09 21:36:14 +02:00
[issue]: https://github.com/davidpdrsn/axum/issues/new