Commit graph

254 commits

Author SHA1 Message Date
David Pedersen
66a806630c Note changes to examples in 0.2 2021-08-21 11:35:57 +02:00
David Pedersen
08544f9d92 Reorganize changelog a bit 2021-08-21 11:35:49 +02:00
David Pedersen
0d8f8b7b6c
Fallback to calling next route if no methods match (#224)
This removes a small foot gun from the routing.

This means matching different HTTP methods for the same route that
aren't defined together now works.

So `Router::new().route("/", get(...)).route("/", post(...))` now
accepts both `GET` and `POST`. Previously only `POST` would be accepted.
2021-08-21 01:00:12 +02:00
David Pedersen
971c0a394a
Revert "Simplify handler trait (#221)" (#223)
This reverts commit 44c58bdf5f.
2021-08-20 23:56:16 +02:00
David Pedersen
f984198440
Add more examples to "Building responses" section (#222)
Someone on reddit suggested adding more examples.
2021-08-20 20:50:11 +02:00
David Pedersen
44c58bdf5f
Simplify handler trait (#221)
Rely on the `impl FromRequest for (T, ...)` rather than extracting things directly inside the macro.
2021-08-20 20:36:34 +02:00
David Pedersen
e8bc3f5082
Further compile time improvements (#220)
This improves compiles further when using lots of nested routes. Such as
the example posted
[here](https://github.com/tokio-rs/axum/issues/200#issuecomment-902541073).

It seems rustc is really slow at checking bounds on these kinds of
intermediate builder methods. Should probably file an issue about that.
2021-08-20 19:51:29 +02:00
Johannes Becker
be61b8c611
Update changelog (#219) 2021-08-20 17:23:44 +02:00
Johannes Becker
7350b817b0
expose tower log feature (#218) 2021-08-20 13:41:28 +02:00
David Pedersen
39a0c26795
Add print-request-response example (#216)
* Add `print-request-response` example

Someone asked about this on Discord. I think its worth adding as an
example.

* add missing feature
2021-08-20 09:26:31 +02:00
David Pedersen
1bda638c6b Simplify 404 example using or 2021-08-19 22:50:42 +02:00
David Pedersen
23dcf3631e Export Or in a more consistent way 2021-08-19 22:44:26 +02:00
David Pedersen
570e13195c Inline Router in root module docs 2021-08-19 22:39:37 +02:00
David Pedersen
ca4d9a2bb9
Replace route with Router::new().route() (#215)
This way there is now only one way to create a router:

```rust
use axum::{Router, handler::get};

let app = Router::new()
    .route("/foo", get(handler))
    .route("/foo", get(handler));
```

`nest` was changed in the same way:

```rust
use axum::Router;

let app = Router::new().nest("/foo", service);
```
2021-08-19 22:37:48 +02:00
David Pedersen
97b53768ba
Replace RoutingDsl trait with Router type (#214)
* Remove `RoutingDsl`

* Fix typo
2021-08-19 21:24:32 +02:00
David Pedersen
0fd17d4181
Bring back Handler::into_service (#212)
It was removed as part of https://github.com/tokio-rs/axum/pull/184 but
I do actually think it has some utility. So makes sense to keep even if
axum doesn't use it directly for routing.
2021-08-19 21:16:44 +02:00
simonborje
421faceae3
Update tokio-tungstenite version (#211)
Co-authored-by: Simon Börjesson <no@address.com>
2021-08-19 14:51:21 +02:00
David Pedersen
0f48f33e9d
Make sure doc tests run on CI (#206)
* Make sure doc tests run on CI

* Run doc tests in separate step

Don't need to run them for stable, beta, nightly
2021-08-19 09:34:48 +02:00
Eduardo Canellas
2d6b5dd0b8
docs: fix typo on EmptyRouter documentation (#204) 2021-08-18 20:30:39 +02:00
David Pedersen
5368e33f99 Remove askama config
Its no longer needed since https://github.com/tokio-rs/axum/pull/201
2021-08-18 14:41:00 +02:00
David Pedersen
e22045d42f
Change nested routes to see the URI with prefix stripped (#197) 2021-08-18 09:48:36 +02:00
Sagi Sarussi
cb637f1124
Fix typo (#202) 2021-08-18 08:02:45 +02:00
David Pedersen
6c9651c14a
Move all examples to their own crates (#201)
This makes it much clearer which dependencies each example has.
2021-08-18 00:49:01 +02:00
David Pedersen
1ae0dee53b Update changelog 2021-08-18 00:04:57 +02:00
Florian Thelliez
d9a06ef14b
Remove axum::prelude (#195) 2021-08-18 00:04:15 +02:00
David Pedersen
f083c3e97e Ignore error in TLS example 2021-08-17 22:17:04 +02:00
David Pedersen
dd0c345040
Improve compile times of handle_error and check_infallible (#198)
* Improve compile times of `handle_error`

This brings the compile time of the example posted [here][example] from
3 seconds down to 0.3 seconds for me.

Having the bounds on the methods does improve UX but not worth
sacrificing 10x compile time for.

[example]: https://github.com/tokio-rs/axum/issues/145#issue-963183256

* Improve compile time of `check_infallible`

* update changelog
2021-08-17 19:07:47 +02:00
David Pedersen
93cdfe8c5f
Work around for http2 hang with Or (#199)
This is a nasty hack that works around
https://github.com/hyperium/hyper/issues/2621.

Fixes https://github.com/tokio-rs/axum/issues/191
2021-08-17 19:00:24 +02:00
David Pedersen
97c140cdf7
Add Headers response (#193)
* Add `Headers`

Example usage:

```rust
use axum::{
    route,
    routing::RoutingDsl,
    response::{IntoResponse, Headers},
    handler::get,
};
use http::header::{HeaderName, HeaderValue};

// It works with any `IntoIterator<Item = (Key, Value)>` where `Key` can be
// turned into a `HeaderName` and `Value` can be turned into a `HeaderValue`
//
// Such as `Vec<(HeaderName, HeaderValue)>`
async fn just_headers() -> impl IntoResponse {
    Headers(vec![
        (HeaderName::from_static("X-Foo"), HeaderValue::from_static("foo")),
    ])
}

// Or `[(&str, &str)]`
async fn from_strings() -> impl IntoResponse {
    Headers([("X-Foo", "foo")])
}
```

Fixes https://github.com/tokio-rs/axum/issues/187

* Make work on Rust versions without `IntoIterator` for arrays

* format

* changelog
2021-08-17 17:28:02 +02:00
David Pedersen
baa99e5084
Make RequestParts::{new, try_into_request} public (#194)
Fixes https://github.com/tokio-rs/axum/issues/147
2021-08-16 20:55:22 +02:00
David Pedersen
b4cbd7f147
Add Redirect response (#192)
* Add `Redirect` response

* Add `Redirect::found`
2021-08-16 19:48:03 +02:00
David Pedersen
dda625759d Fix import 2021-08-16 17:29:47 +02:00
David Pedersen
a128a672a1
Remove allocation when calling handler (#190)
`Handler::call` already returns a boxed future so we don't have to box
it again.
2021-08-16 09:19:37 +02:00
Eduardo Canellas
57e440ed2e
move relevant docs sections to be under "Routing" (#175) 2021-08-16 09:17:26 +02:00
David Pedersen
be7e9e9bc6
Refactor TypedHeader extractor (#189)
I should use `HeaderMapExt::typed_try_get` rather than implementing it
manually.
2021-08-16 09:05:10 +02:00
David Pedersen
48afd30491
Improve compile times (#184)
* Inline `handler::IntoService`

* Inline `BoxResponseBody`

* Add missing debug impl
2021-08-15 23:01:26 +02:00
Harrison Burt
292d174a73
correct hyper link to add the .rs suffix. (#183)
This fixes the broken redirect for `tracing_aka_logging` which current redirects to what it thinks is a folder instead of a file, resulting in a 404.
2021-08-15 22:55:33 +02:00
David Pedersen
995ffc1aa2
Correctly handle HEAD requests (#129) 2021-08-15 20:27:13 +02:00
Kai Jewson
9cd543401f
Implement SSE using responses (#98) 2021-08-14 17:29:09 +02:00
Paolo Barbolini
045287aef9
Reduce futures-util features (#173) 2021-08-10 20:08:44 +02:00
David Pedersen
594052dc48 Revert hello_world example
Accidentally changed it while testing something
2021-08-10 10:03:29 +02:00
David Pedersen
8ef96f2199 Add test for routing matching multiple methods
I don't believe we had a test for this
2021-08-10 10:02:40 +02:00
Richard Janis Goldschmidt
387de8b426
Use tower http auth layer in kv store example (#171) 2021-08-10 09:46:09 +02:00
David Pedersen
a790abca87 More consistent docs 2021-08-08 20:26:42 +02:00
David Pedersen
8500ea256d
Implement FromRequest for http::Extensions (#169)
Not sure its very useful but odd to not provide this. All other request
parts have an extractor and we already have the rejection for it.
2021-08-08 20:01:06 +02:00
David Pedersen
6b218c7150
Clean up RequestParts API (#167)
In http-body 0.4.3 `BoxBody` implements `Default`. This allows us to
clean up the API of `RequestParts` quite a bit.
2021-08-08 19:48:30 +02:00
David Pedersen
bc27b09f5c
Make sure nested services still see full URI (#166)
They'd previously see the nested URI as we mutated the request. Now we
always route based on the nested URI (if present) without mutating the
request. Also meant we could get rid of `OriginalUri` which is nice.
2021-08-08 17:27:23 +02:00
fluunke
0674c9136a
Add oauth2 example (#144) 2021-08-08 17:22:24 +02:00
David Pedersen
d89d061724
Move some files to mod.rs (#165)
I prefer this setup but didn't wanna do it while there were too many
open PRs.
2021-08-08 16:54:03 +02:00
David Pedersen
b75b7b0184
Re-export more body utilities (#162)
Useful when implementing `IntoResponse`
2021-08-08 16:41:17 +02:00