Commit graph

98 commits

Author SHA1 Message Date
David Pedersen
72071cf5de
Implement MethodFilter via bitflags (#158)
Fixes https://github.com/tokio-rs/axum/issues/107
2021-08-07 23:05:53 +02:00
Jonas Platte
6a042a9b3a
Cleanup CI (#141)
* Feature-gate test that depends on non-default features

Makes `cargo check` work without extra flags.

* Don't set doc(html_root_url)

It is no longer recommended:
https://github.com/rust-lang/api-guidelines/pull/230

* Remove documentation URL from Cargo.toml

crates.io will link to the right version on docs.rs automatically.

* Ensure toolchains installed by actions-rs/toolchain are actually used

* Fix missing rustup component in check job

* Raise MSRV to 1.51

Older versions weren't actually working before.

* Only run clippy & rustfmt on stable toolchain

MSRV is checked in test-versions.

* Allow cargo doc to succeed without headers and multipart features

CI will still ensure that intra-doc links that rely on these are not broken.
2021-08-07 11:06:42 +02:00
David Pedersen
e13f1da11d
Version 0.1.3 (#139)
- Fix stripping prefix when nesting services at `/` ([#91](https://github.com/tokio-rs/axum/pull/91))
- Add support for WebSocket protocol negotiation ([#83](https://github.com/tokio-rs/axum/pull/83))
- Use `pin-project-lite` instead of `pin-project` ([#95](https://github.com/tokio-rs/axum/pull/95))
- Re-export `http` crate and `hyper::Server` ([#110](https://github.com/tokio-rs/axum/pull/110))
- Fix `Query` and `Form` extractors giving bad request error when query string is empty. ([#117](https://github.com/tokio-rs/axum/pull/117))
- Add `Path` extractor. ([#124](https://github.com/tokio-rs/axum/pull/124))
- Fixed the implementation of `IntoResponse` of `(HeaderMap, T)` and `(StatusCode, HeaderMap, T)` would ignore headers from `T` ([#137](https://github.com/tokio-rs/axum/pull/137))
- Deprecate `extract::UrlParams` and `extract::UrlParamsMap`. Use `extract::Path` instead ([#138](https://github.com/tokio-rs/axum/pull/138))
2021-08-06 11:20:42 +02:00
Sunli
09ecd42b32
Add async-graphql example (#93)
Fixes https://github.com/tokio-rs/axum/issues/68
2021-08-04 12:10:20 +02:00
Sunli
be68227d73
Use pin-project-lite instead of pin-project (#95) 2021-08-03 09:33:00 +02:00
David Pedersen
9fbababc3a
Make it clear how to run all examples (#92)
* Handle errors in websocket example

* Make it clear how to run all examples
2021-08-02 23:09:09 +02:00
Javier Viola
c6b7ad0f33
Add chat example documentation. (#85) 2021-08-02 21:42:10 +02:00
minghuaw
ee9032b9d1
Changed http-body dependency version to 0.4.2 (#81) 2021-08-01 23:09:08 +02:00
David Pedersen
55c1a29420
Version 0.1.2 (#80) 2021-08-01 22:13:43 +02:00
David Pedersen
6d787665d6
Server-Sent Events (#75)
Example usage:

```rust
use axum::{prelude::*, sse::{sse, Event, KeepAlive}};
use tokio_stream::StreamExt as _;
use futures::stream::{self, Stream};
use std::{
    time::Duration,
    convert::Infallible,
};

let app = route("/sse", sse(make_stream).keep_alive(KeepAlive::default()));

async fn make_stream(
    // you can also put extractors here
) -> Result<impl Stream<Item = Result<Event, Infallible>>, Infallible> {
    // A `Stream` that repeats an event every second
    let stream = stream::repeat_with(|| Event::default().data("hi!"))
        .map(Ok)
        .throttle(Duration::from_secs(1));

    Ok(stream)
}
```

Implementation is based on [warp's](https://github.com/seanmonstar/warp/blob/master/src/filters/sse.rs)
2021-08-01 21:49:17 +02:00
David Pedersen
ea82acd175
Add sessions and cookies examples (#65)
Uses [`async-session`](https://crates.io/crates/async-session).
2021-08-01 09:15:44 +02:00
programatik29
3b579c7215
Add TLS example (with rustls) (#57) 2021-08-01 08:32:47 +02:00
David Pedersen
f67abd1ee2
Add extractor for remote connection info (#55)
Fixes https://github.com/tokio-rs/axum/issues/43

With this you can get the remote address like so:

```rust
use axum::{prelude::*, extract::ConnectInfo};
use std::net::SocketAddr;

let app = route("/", get(handler));

async fn handler(ConnectInfo(addr): ConnectInfo<SocketAddr>) -> String {
    format!("Hello {}", addr)
}

// Starting the app with `into_make_service_with_connect_info` is required
// for `ConnectInfo` to work.
let make_svc = app.into_make_service_with_connect_info::<SocketAddr, _>();

hyper::Server::bind(&"0.0.0.0:3000".parse().unwrap())
    .serve(make_svc)
    .await
    .expect("server failed");
```

This API is fully generic and supports whatever transport layer you're using with Hyper. I've updated the unix domain socket example to extract `peer_creds` and `peer_addr`.
2021-07-31 21:36:30 +02:00
David Pedersen
6c1279a415 Version 0.1.1 2021-07-30 17:20:38 +02:00
David Pedersen
272e22a23b Release prep 2021-07-30 15:56:01 +02:00
David Pedersen
ba9c03d146 Update links 2021-07-22 19:39:08 +02:00
David Pedersen
6705e79ed7
Add todos example (#38) 2021-07-22 15:38:32 +02:00
David Pedersen
028c472c84
Add Multipart extractor for consuming multipart/form-data requests (#32)
Multipart implementation on top of `multer`
2021-07-14 16:53:37 +02:00
David Pedersen
e641caefaf
Remove hyper-h1 and hyper-h2 features (#31) 2021-07-14 16:29:06 +02:00
David Pedersen
5a5710d290
Rename to axum (#28) 2021-07-09 21:36:14 +02:00
David Pedersen
c4d266e94d
Allow errors (#26)
This changes error model to actually allow errors. I think if we're going to use this for things like tonic's route we need a more flexible error handling model. The same `handle_error` adaptors are still there but services aren't required to have `Infallible` as their error type. The error type is simply propagated all the way through.
2021-07-05 16:18:39 +02:00
David Pedersen
356f1c8424
Generic request body (#22)
Fixes #21
2021-06-19 12:50:33 +02:00
David Pedersen
6a16cd40ca
Add error handling and dependency injection example (#23) 2021-06-19 12:34:42 +02:00
David Pedersen
8a82fd00aa
Add bb8 connection pool example (#19)
I figure this will be quite common.
2021-06-15 22:25:41 +02:00
David Pedersen
b6e67eefd7
Add support for extracting typed headers (#18)
Uses the `headers` crate.
2021-06-15 21:27:21 +02:00
David Pedersen
2f6699aeae
Add HTML template example (#17) 2021-06-13 13:58:12 +02:00
David Pedersen
1002685a20
Rename to awebframework (#13) 2021-06-13 11:22:02 +02:00
David Pedersen
04d62798b6
Reduce body boxing (#9)
Previously, when routing between one or two requests the two body types
would be merged by boxing them. This isn't ideal since it introduces a
layer indirection for each route.

We can't require the services to be routed between as not all services
use the same body type.

This changes that so it instead uses an `Either` enum that implements
`http_body::Body` if each variant does. Will reduce the overall
allocations and hopefully the compiler can optimize things if both
variants are the same.
2021-06-12 23:59:18 +02:00
David Pedersen
b3bc4e024c
Add RoutingDsl::{serve, into_make_service} (#8) 2021-06-12 21:44:40 +02:00
David Pedersen
c9c507aece
Add support for websockets (#3)
Basically a copy/paste of whats in warp.

Example usage:

```rust
use tower_web::{prelude::*, ws::{ws, WebSocket}};

let app = route("/ws", ws(handle_socket));

async fn handle_socket(mut socket: WebSocket) {
    while let Some(msg) = socket.recv().await {
        let msg = msg.unwrap();
        socket.send(msg).await.unwrap();
    }
}
```
2021-06-12 20:50:30 +02:00
David Pedersen
002e3f92b3
Misc repo setup (#7) 2021-06-12 20:18:21 +02:00
David Pedersen
099e886575 Notes on backpressure 2021-06-08 23:55:25 +02:00
David Pedersen
21872c9f7a Remove some unnecessary dependencies 2021-06-08 22:27:38 +02:00
David Pedersen
1f8b39f05d More docs and expand key_value_store example 2021-06-08 12:43:16 +02:00
David Pedersen
a005427d40 Write some docs 2021-06-06 15:19:54 +02:00
David Pedersen
c3977d0b71 Change routing DSL 2021-06-04 01:00:48 +02:00
David Pedersen
00737c4e0a checkpoint 2021-06-02 22:07:37 +02:00
David Pedersen
ea582ab8d9 Quality of life improvements 2021-06-01 14:52:18 +02:00
David Pedersen
f690e74275 Support nesting services with error handling 2021-06-01 11:23:56 +02:00
David Pedersen
f6b1a6f435 More work 2021-05-31 16:28:26 +02:00
David Pedersen
593c901aab Start writing more tests 2021-05-31 12:22:16 +02:00
David Pedersen
7328127a3d Add example 2021-05-30 14:33:36 +02:00
David Pedersen
2e16842431 Add extension extractor 2021-05-30 11:07:56 +02:00
David Pedersen
b763eaa037 Fix layer support 2021-05-30 04:28:24 +02:00
David Pedersen
f983b37fea Support routing to tower services 2021-05-30 03:12:47 +02:00
David Pedersen
a04c98dd42 Support any type of response body 2021-05-30 01:57:01 +02:00
David Pedersen
0513b56faf better readiness handling and less boxing 2021-05-30 01:11:18 +02:00
David Pedersen
07294378b3 Initial pile of hacks 2021-05-29 21:13:06 +02:00