Commit graph

1385 commits

Author SHA1 Message Date
David Pedersen
b1e7a6ae7b
Enable CI caching (#149) 2021-08-07 17:09:30 +02:00
David Pedersen
95d7582d28
Fix ServiceExt::handle_error footgun (#120)
As described in
https://github.com/tokio-rs/axum/pull/108#issuecomment-892811637, a
`HandleError` created from `axum::ServiceExt::handle_error` should _not_
implement `RoutingDsl` as that leads to confusing routing behavior.

The technique used here of adding another type parameter to
`HandleError` isn't very clean, I think. But the alternative is
duplicating `HandleError` and having two versions, which I think is less
desirable.
2021-08-07 16:44:12 +02:00
David Pedersen
b5b9db47db
Remove QueryStringMissing as it was no longer being used (#125)
* Remove `QueryStringMissing` as it was no longer being used

* remove it in a few more places
2021-08-07 16:31:51 +02:00
David Pedersen
123b1b3c5e
Remove future re-exports (#133)
These types were moved around in
https://github.com/tokio-rs/axum/pull/130 but re-export from their old
location for backwards compatibility.

This removes the re-exports.
2021-08-07 16:22:53 +02:00
David Pedersen
a0a19c8362
Remove Copy some impls (#132)
https://github.com/tokio-rs/axum/pull/129 was a breaking change, in part
because I had to remove the `Copy` impl from `OnMethod`.

For the sake of future proofing I think we should remove other `Copy`
impls from services as well. We can always bring them back once things
have matured more.

These types no longer implement `Copy`:

- `EmptyRouter`
- `ExtractorMiddleware`
- `ExtractorMiddlewareLayer`
2021-08-07 16:13:56 +02:00
David Pedersen
d7d97a613e Adjust Json docs 2021-08-07 16:10:07 +02:00
Sunli
345163e98d
Common JSON wrapper type for response and request (#140) 2021-08-07 16:07:13 +02:00
David Pedersen
3d45a97db9
Make FromRequest default to use axum::body::Body (#146)
Most users will implement `FromRequest<axum::body::Body>` so making that
the default makes things a bit easier to use.
2021-08-07 12:22:14 +02:00
David Pedersen
5922c4fa50 Run CI for main
...and not `master`
2021-08-07 11:11:29 +02:00
David Pedersen
904227419c Fix tests for 1.51
They used array `IntoIterator`.
2021-08-07 11:08:20 +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
David Pedersen
811b1d896c
Deprecate extract::UrlParams and extract::UrlParamsMap (#138)
Use `extract::Path` instead. It supports everything the two other do,
and more.
2021-08-06 10:38:38 +02:00
Sunli
a0ac8a5b78
Fixed the implementation of IntoResponse of (HeaderMap, T) and (StatusCode, HeaderMap, T) would ignore headers from T (#137)
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2021-08-06 10:31:38 +02:00
Sunli
9fdbd42fba
Implement path extractor (#124)
Fixes #42
2021-08-06 10:17:57 +02:00
David Pedersen
2be79168d8
Handle METHOD_NOT_ALLOWED in 404 example (#131)
If a route existed but had no handler for the method, the code used in
the 404 example wouldn't catch it.
2021-08-06 01:15:23 +02:00
David Pedersen
d4ce90e2e6
Move response futures into their own modules (#130)
It cleans up the docs to have the futures in their own modules as users
are unlikely to look at them. Also matches the pattern used in tower
https://docs.rs/tower/0.4.8/tower/util/future/index.html.

Added re-exports to the old locations so its not a breaking change.
2021-08-06 01:15:10 +02:00
Laurențiu Nicola
68f826ef3b
Simplify tracing-subscriber initialization (#128) 2021-08-05 19:43:03 +02:00
Grzegorz Baranski
f18e423fb0
docs: add community showcase (#126) 2021-08-05 13:47:19 +02:00
David Pedersen
1509d4ad12 Add note about safety to readme 2021-08-05 11:51:33 +02:00
Spencer Gilbert
3cd0c0fd45
Set RUST_LOG environment var for all examples using tracing (#123)
* Set RUST_LOG environment var for all examples using tracing

Signed-off-by: Spencer Gilbert <spencer.gilbert@gmail.com>

* Update examples/multipart_form.rs

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2021-08-05 11:25:03 +02:00
David Pedersen
a8eb26b672 Fix typos in rejection messages 2021-08-05 08:36:42 +02:00
David Pedersen
a95b48b70c
Deprecate QueryStringMissing (#119)
Since https://github.com/tokio-rs/axum/pull/117 its no longer used. Will
be removed in 0.2.
2021-08-04 17:58:34 +02:00
Sunli
fb0b3b78eb
Fix Query and Form extractors giving bad request error when query string is empty (#117)
Co-Authored-By: David Pedersen <david.pdrsn@gmail.com>

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2021-08-04 17:13:09 +02:00
David Pedersen
5c12328892
Replace hyper::Server with axum::Server in docs (#118)
* Replace `hyper::Server` with `axum::Server` in docs

* Change readme as well
2021-08-04 15:38:51 +02:00
David Pedersen
cffdedc055 Move comments in docs outside code block 2021-08-04 15:07:04 +02:00
David Pedersen
96fac52519 Make docs on required deps more clear 2021-08-04 15:06:47 +02:00
Sunli
7cf8dafdce
Re-export http crate and hyper::Server (#110)
Co-Authored-By: David Pedersen <david.pdrsn@gmail.com>

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2021-08-04 12:29:42 +02:00
Jonas Platte
d285dfb568
Tell clippy about MSRV (#114)
* Remove unused import

* Tell clippy about MSRV
2021-08-04 12:15:58 +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
Jonas Platte
015f6e0c21
Fix typos found by typos-cli (#113) 2021-08-04 12:09:39 +02:00
Grzegorz Baranski
4e9b38ddf9
Use tuple destructuring in chat example (#105) 2021-08-03 22:21:18 +02:00
David Pedersen
9a6bc4e962
Break up extract.rs (#103)
This breaks up `extract.rs` into several smaller submodules. The public
API remains the same.

This is done in prep for adding more tests to extractors which would get
messy if they were all in the same file.
2021-08-03 21:55:48 +02:00
PatatasDelPapa
715e624d8c
Remove unused imports from example (#104)
Remove unused imports from the first crate documentation example.
2021-08-03 21:55:27 +02:00
David Pedersen
f84f52d61e Contributing guide fixes 2021-08-03 21:44:49 +02:00
Mateusz Kieblesz
b0457c08e8
Add 404 page example (#97) 2021-08-03 17:00:21 +02:00
Sunli
be68227d73
Use pin-project-lite instead of pin-project (#95) 2021-08-03 09:33:00 +02:00
Sunli
ba74787532
Add support for WebSocket protocol negotiation. (#83) 2021-08-03 08:43:37 +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
David Pedersen
6a078ddb71
Fix stripping prefix when nesting at / (#91)
* Fix stripping prefix when nesting at `/`

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

* changelog
2021-08-02 22:40:33 +02:00
Javier Viola
c6b7ad0f33
Add chat example documentation. (#85) 2021-08-02 21:42:10 +02:00
David Pedersen
a0f6dccc5e Remove dbg! left in by accident 2021-08-02 09:46:08 +02:00
minghuaw
ee9032b9d1
Changed http-body dependency version to 0.4.2 (#81) 2021-08-01 23:09:08 +02:00
programatik29
ffefb3455c
Add chat example (#78) 2021-08-01 22:42:34 +02:00
David Pedersen
55c1a29420
Version 0.1.2 (#80) 2021-08-01 22:13:43 +02:00
David Pedersen
666d088b26
Including tracing setup in all examples (#79) 2021-08-01 22:01:33 +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
c232c56de0
Mention required dependencies in docs (#77)
Fixes https://github.com/tokio-rs/axum/issues/70
2021-08-01 21:33:55 +02:00
David Pedersen
69ae7a686a
Fix websockets failing on Firefox (#76)
Axum expected the `Connection` header to be _exactly_ `upgrade`. Turns
out thats a bit too strict as this didn't work in Firefox.

Turns out `Connection` just has to contain `upgrade`. At least that is
what [warp does](https://github.com/seanmonstar/warp/blob/master/src/filters/ws.rs#L46).
2021-08-01 21:00:38 +02:00
jtroo
10bedca796
Fix typos in service docs (#74)
This commit fixes some typos and improves the grammar/structure
of some sections.
2021-08-01 20:55:09 +02:00