Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/carllerche/tower-web
A fast, boilerplate free, web framework for Rust
https://github.com/carllerche/tower-web
Last synced: 7 days ago
JSON representation
A fast, boilerplate free, web framework for Rust
- Host: GitHub
- URL: https://github.com/carllerche/tower-web
- Owner: carllerche
- License: mit
- Created: 2018-03-12T22:31:22.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-12-06T22:03:32.000Z (about 5 years ago)
- Last Synced: 2024-05-02T00:53:33.994Z (8 months ago)
- Language: Rust
- Homepage:
- Size: 605 KB
- Stars: 975
- Watchers: 38
- Forks: 54
- Open Issues: 84
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rust-cn - carllerche/tower-web - web](https://crates.io/crates/tower-web)] — A fast, boilerplate free, web framework for Rust [<img src="https://api.travis-ci.org/carllerche/tower-web.svg?branch=master">](https://travis-ci.org/carllerche/tower-web) (Libraries / Web programming)
- awesome-rust - carllerche/tower-web - web](https://crates.io/crates/tower-web)] — A fast, boilerplate free, web framework for Rust [<img src="https://api.travis-ci.org/carllerche/tower-web.svg?branch=master">](https://travis-ci.org/carllerche/tower-web) (Libraries / Web programming)
- awesome-rust - carllerche/tower-web - web](https://crates.io/crates/tower-web)] — A fast, boilerplate free, web framework (Libraries / Web programming)
- awesome-rust-cn - carllerche/tower-web - web](https://crates.io/crates/tower-web)] (库 Libraries / 网络编程 Web programming)
- awesome-list - tower-web
- awesome-rust-zh - carllerche/tower-web - web](https://crates.io/crates/tower-web)]-一个快速的,样板自由,螃蟹的网络框架[<img src="https://api.travis-ci.org/carllerche/tower-web.svg?branch=master">](https://travis-ci.org/carllerche/tower-web) (库 / 网页编程)
README
# Tower Web
A web framework for Rust with a focus on removing boilerplate.
[![Build Status](https://travis-ci.org/carllerche/tower-web.svg?branch=master)](https://travis-ci.org/carllerche/tower-web)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Crates.io](https://img.shields.io/crates/v/tower-web.svg?maxAge=2592000)](https://crates.io/crates/tower-web)
[![Gitter](https://badges.gitter.im/tower-rs/tower.svg)](https://gitter.im/tower-rs/tower)[API Documentation][dox]
Tower Web is:
* **Fast**: Fully asynchronous, built on [Tokio] and [Hyper].
* **Ergonomic**: Tower-web decouples HTTP from your application logic, removing
all boilerplate.
* **Works on Rust stable**: You can use it today.[Tokio]: https://github.com/tokio-rs/tokio
[Hyper]: http://github.com/hyperium/hyper
[dox]: https://docs.rs/tower-web/0.3.7/tower_web/## Hello World
```rust
#[macro_use]
extern crate tower_web;
extern crate tokio;use tower_web::ServiceBuilder;
use tokio::prelude::*;/// This type will be part of the web service as a resource.
#[derive(Clone, Debug)]
struct HelloWorld;/// This will be the JSON response
#[derive(Response)]
struct HelloResponse {
message: &'static str,
}impl_web! {
impl HelloWorld {
#[get("/")]
#[content_type("json")]
fn hello_world(&self) -> Result {
Ok(HelloResponse {
message: "hello world",
})
}
}
}pub fn main() {
let addr = "127.0.0.1:8080".parse().expect("Invalid address");
println!("Listening on http://{}", addr);ServiceBuilder::new()
.resource(HelloWorld)
.run(&addr)
.unwrap();
}
```## Overview
Tower Web aims to decouple all HTTP concepts from the application logic. You
define a "plain old Rust method" (PORM?). This method takes only the data it
needs to complete and returns a struct representing the response. Tower Web does
the rest.The `impl_web` macro looks at the definition and generates the glue code,
allowing the method to respond to HTTP requests.## Getting Started
The best way to get started is to read the [examples] and [API docs][dox].
[dox]: #
[examples]: examples/## License
This project is licensed under the [MIT license](LICENSE).
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in `tower-web` by you, shall be licensed as MIT, without any
additional terms or conditions.