• Stars
    star
    974
  • Rank 47,011 (Top 1.0 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 6 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A fast, boilerplate free, web framework for Rust

Tower Web

A web framework for Rust with a focus on removing boilerplate.

Build Status License: MIT Crates.io Gitter

API Documentation

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.

Hello World

#[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<HelloResponse, ()> {
            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.

License

This project is licensed under the MIT 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.

More Repositories

1

codegen

A Rust library providing a builder API to generate Rust code.
Rust
245
star
2

eventual

A future & stream abstraction for Rust
Rust
241
star
3

astaire-old

The basic Sinatra DSL inside of ActionController
Ruby
158
star
4

syncbox

Concurrency utilities for Rust
Rust
131
star
5

vimrc

My vim files (i'm a n00b, don't use these)
Vim Script
99
star
6

tokio-serde

Rust
74
star
7

kabuki

Lightweight actor system built on top of Tokio
Rust
73
star
8

rack-router

Ruby
61
star
9

iovec

Rust library providing a specialized byte slice type for performing vectored I/O operations.
Rust
50
star
10

pool

A pool of reusable values
Rust
49
star
11

eventual_io

Async IO based around Futures & Streams
Rust
48
star
12

futures-pool

Work-stealing thread pool for executiong futures
Rust
41
star
13

mini-raft

An implementation of Raft in Rust.
Rust
38
star
14

string

Rust String type with configurable byte storage.
Rust
32
star
15

tokio-serde-json

Rust
22
star
16

better-future

Extra utilities for working with futures-rs
Rust
20
star
17

two-lock-queue

A MPMC channel based on the two lock queue algorithm
Rust
16
star
18

minidb

Rust
16
star
19

automaton

Rust library for parsing regular languages
Rust
15
star
20

futures-broadcast

Futures aware pub/sub channel
Rust
14
star
21

tokio-connect

Connect an AsyncRead + AsyncWrite
Rust
13
star
22

mock-io

Rust mock type implementing io::Read & io::Write
Rust
13
star
23

mio-more

Code that was deprecated from Mio
Rust
11
star
24

shipit

Rust
11
star
25

utp

Rust
11
star
26

astaire

WIP - Don't look!
Rust
11
star
27

futures-threadpool

An implementation of thread pools which can be used with Rust futures
Rust
11
star
28

travis-rust-matrix

Example of how to configure a Rust crate for matrix builds on travis
Shell
10
star
29

thread-pool

Rust
9
star
30

echo-benchmarks

Blocking vs. async echo server benchmarks
Rust
9
star
31

futures-mpsc

Future aware MPSC channel
Rust
8
star
32

futures-spawn

Spawn futures
Rust
8
star
33

mio-examples

A collection of MIO examples.
Rust
8
star
34

minifmt

Minimally format Rust code
Rust
8
star
35

.emacs.d

Emacs Lisp
7
star
36

syncbox-next

Concurrency utilities for Rust
Rust
7
star
37

futures-borrow

Futures-aware borrow cell
Rust
7
star
38

pidfile-rust

Handles managing a pidfile for daemon mutual exclusion
Rust
6
star
39

automata

A (very experimental) finite state machine library for clojure
Clojure
5
star
40

hdrgen-rust

Generate C headers from externed rust fns.
Rust
5
star
41

tokio-mock-task

Test utility for mocking a Tokio task
Rust
5
star
42

buffoon

A protobuf library for Rust
Rust
4
star
43

bytes-more

Extra utility types / helpers for working with the bytes crate
Rust
4
star
44

assertive

Collections of Rust assertions
Rust
4
star
45

take

A container utility for Rust
Rust
3
star
46

tokio-examples

Rust
3
star
47

ios-test-harness

Test harness for running Rust tests in the simulator
Objective-C
3
star
48

http-macros

Macros for creating HTTP types
Rust
3
star
49

http-util

Additional utilities for use with the `http` Rust crate.
Rust
2
star
50

futures-machines

Future combinators usable at the state machine level.
Rust
2
star
51

hashmap2

Fork of std::collections::HashMap
Rust
2
star
52

tokio-event

Rust
2
star
53

tokio-repro

Rust
2
star
54

io-dump

Wraps an I/O handle, logging all activity in a readable format to a configurable destination.
Rust
2
star
55

fixture-io

An implementation of std::io::Read, std::io::Write, and tokio_core::io::Io that runs a predefined script
Rust
2
star
56

tower-lambda

Bridges tower and lambda
Rust
1
star
57

scoped-mut-tls

Rust
1
star
58

website

My personal website
SCSS
1
star
59

tokio-test

Testing utilities for usage with TOkio
Rust
1
star
60

turmoil-cli

Rust
1
star
61

pin-convert

Traits for converting to `Pin` variants.
Rust
1
star
62

hash-table

Raw hash table for Rust
Rust
1
star
63

hashmap3

HashMap that works on stable Rust.
Rust
1
star
64

aws-tools

CLI tools for AWS based on fog
Ruby
1
star
65

hello-axum

A basic axum service
Dockerfile
1
star
66

experiment-vendor-tower

Rust
1
star
67

stable-heap

Heap APIs for stable Rust
Rust
1
star
68

futures-ext

Rust
1
star
69

turbowish-mocks

Rust
1
star