MCPcopy Index your code
hub / github.com/carllerche/tower-web

github.com/carllerche/tower-web @v0.3.6

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.3.6 ↗ · + Follow
787 symbols 1,789 edges 135 files 159 documented · 20%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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.

Extension points exported contracts — how you extend this code

Extract (Interface)
Extract a value from an HTTP request. The extracted value does not need to be produced immediately. Implementations of [7 …
src/extract/mod.rs
Response (Interface)
Types that can be returned from resources as responses to HTTP requests. Implementations of `Response` are responsible [22 …
src/response/response.rs
Resource (Interface)
A `Resource` processes HTTP requests received by the service. A single service is composed of one or more resources. A [13 …
src/routing/resource.rs
Chain (Interface)
Combine two values This trait is used to represent types that can be chained, including middleware and resource values. [14 …
src/util/chain.rs
Middleware (Interface)
Decorates a `Service`, transforming either the request or the response. Often, many of the pieces needed for writing ne [5 …
src/middleware/middleware.rs
Connection (Interface)
A stream between a local and remote target. [2 implementers]
src/net.rs
Catch (Interface)
Handles an error generated by a resource method. In the event that an error occurs while processing an HTTP request, im [2 …
src/error/catch.rs
TestHttpService (Interface)
(no doc) [1 implementers]
tests/support/mod.rs

Core symbols most depended-on inside this repo

map
called by 534
src/routing/set.rs
clone
called by 123
src/error/catch.rs
insert_all
called by 78
src/routing/set.rs
poll
called by 78
src/util/tuple.rs
call_unwrap
called by 55
tests/support/mod.rs
service
called by 46
tests/support/mod.rs
header
called by 45
src/response/content_type.rs
len
called by 30
src/routing/captures.rs

Shape

Method 416
Function 157
Class 156
Enum 33
Interface 25

Languages

Rust100%

Modules by API surface

src/middleware/cors/config.rs45 symbols
src/util/tuple.rs39 symbols
tower-web-macros/src/resource/resource.rs33 symbols
tests/response.rs26 symbols
src/error/error.rs24 symbols
tower-web-macros/src/resource/attr.rs21 symbols
tower-web-macros/src/derive/response.rs21 symbols
tests/extract.rs18 symbols
src/response/context.rs14 symbols
src/middleware/cors/service.rs13 symbols
tower-web-macros/src/resource/route.rs12 symbols
tower-web-macros/src/derive/test/response.rs12 symbols

For agents

$ claude mcp add tower-web \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact