1
0
Fork 0
mirror of https://github.com/tokio-rs/axum.git synced 2024-12-28 15:30:16 +01:00
Commit graph

818 commits

Author SHA1 Message Date
David Pedersen
cc4ae6b297
Improve performance of BoxRoute ()
* Improve performance of `BoxRoute`

This is based on  but slightly shorter.

It removes the need for a `tower::buffer::Buffer` in `BoxRoute` which
improves performance.

* changelog

Co-authored-by: Programatik <programatik29@gmail.com>
2021-10-02 13:43:59 +00:00
David Pedersen
7fae35020a
Version 0.2.6 () 2021-10-02 11:33:52 +00:00
David Pedersen
038c17a514
Add Customizing extractor responses section to docs ()
Should make the example easier easier to find for some.
2021-10-02 11:19:32 +00:00
David Pedersen
f8154a088c
Add example showing up to customize extractor error ()
Lots have been asking about this so makes sense to have an example for.

Once this is merged I'll add a link to it in the docs.
2021-09-30 17:55:58 +00:00
LT
3adc8d733d
Add validator example () 2021-09-28 18:12:23 +02:00
LT
0b3ee5b2ce
Add graceful shutdown example () 2021-09-28 09:08:49 +00:00
David Pedersen
f3c155bf5b
Fix typo in StreamBody docs () 2021-09-22 14:20:43 +00:00
Imbolc
4be4e1d17c
Fix doc typo () 2021-09-22 14:07:26 +00:00
David Pedersen
48401f2c8d
Simplify macros for implementing Handler and FromRequest ()
Makes the generated docs nicer and avoids having a recursive macro.
2021-09-19 15:51:25 +00:00
David Pedersen
0b9e0c7508
Refactor internal testing setup ()
This changes the test setup to use our own client rather than using
reqwest directly. Allows us to add several quality of life features like
always unwrapping results.
2021-09-19 09:38:34 +00:00
David Pedersen
2a683417d1
Clarify what handler::any and service::any accepts ()
They only accept standard HTTP methods and don't think we can fix that
without breaking changes.

Fixes https://github.com/tokio-rs/axum/issues/289
2021-09-19 08:28:15 +00:00
David Pedersen
bb5bcab116
Version 0.2.5 ()
- Add accessors for `TypedHeaderRejection` fields ([])
- Improve docs for extractors ([])

[]: https://github.com/tokio-rs/axum/pull/317
[]: https://github.com/tokio-rs/axum/pull/327
2021-09-18 19:35:10 +02:00
David Pedersen
593e3e319a
Improve extractor docs ()
* Improve extractor docs

- Moves things from the `extract` module docs to the root module docs to
  make them more discoverable
- Adds section showing commonly used extractors
- More clarity around multiple extractors that mutate the request

* english...
2021-09-18 19:09:53 +02:00
Olivier Pinon
0c18caa10f
Add accessors to TypedHeaderRejection fields ()
Fixes 
2021-09-12 16:11:51 +00:00
Andrei Zolkin
9df57e6ff2
Migrate all examples to use std::env::var_os () 2021-09-12 17:39:43 +02:00
heliumbrain
3741e16cf2
Fix typos in docs ()
* Fix typo in docs

Typos for FromRequest

* One more typo
2021-09-12 14:25:25 +00:00
David Pedersen
4e088b40f6
Show how to configure TraceLayer ()
This isn't very obvious so makes sense to include in the example
2021-09-10 17:56:00 +00:00
David Pedersen
36665793c3
Version 0.2.4 ()
Contains some documentation improvements:

- Document using `StreamExt::split` with `WebSocket` ([])
- Document adding middleware to multiple groups of routes ([])

[]: https://github.com/tokio-rs/axum/pull/291
[]: https://github.com/tokio-rs/axum/pull/293
2021-09-10 16:01:14 +00:00
silvioprog
6c13b22cd4
Add JWT example () ()
Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>
2021-09-10 17:51:20 +02:00
Andrei Zolkin
283bbfbd36
Add JWT auth example as community showcase () 2021-09-08 06:15:17 +00:00
techno-tanoC
c8a44105c2
Fix a pull request link in CHANGELOG.md () 2021-09-07 06:33:08 +00:00
Singee
e069225559
fix examples link in README.md () 2021-09-06 07:29:32 +00:00
zhihanz
835432b5c9
Add datafuse as community showcase () 2021-09-02 08:16:49 +02:00
Sidharth Kshatriya
39c5cc24fa
Remove repeated constraint ()
The constraint for B is repeated. Remove it.
2021-08-31 08:23:59 +00:00
David Pedersen
e698586193
Document adding middleware to multiple groups of routes () 2021-08-31 07:07:57 +00:00
David Pedersen
c082107fb6
Document using StreamExt::split with WebSocket ()
Fixes https://github.com/tokio-rs/axum/issues/283
2021-08-30 21:13:50 +00:00
Ken-Miura
c7c73a0d72
Fix a typo in documentation () 2021-08-27 20:20:59 +02:00
Jonas Platte
e41bac7f39
Expose hyper's http2 feature flag ()
* Order features alphabetically

… in Cargo.toml and crate docs.

* Improve ws feature docs

* Expose hyper's http2 feature flag
2021-08-27 08:58:50 +00:00
David Pedersen
4c5068c01f
Add Send + Sync check to all services ()
Should prevent us accidentally introducing breaking changes.

Fixes https://github.com/tokio-rs/axum/issues/275
2021-08-26 20:59:55 +02:00
Ken-Miura
e6ca9e4b04
Fix content-type in example response () 2021-08-26 18:16:41 +00:00
David Pedersen
bdc39deef2
Version 0.2.3 ()
0.2.3 (26. August, 2021)

- **fixed:** Fix accidental breaking change introduced by internal refactor.
  `BoxRoute` used to be `Sync` but was accidental made `!Sync` ([](https://github.com/tokio-rs/axum/pull/273))
2021-08-26 16:22:47 +02:00
David Pedersen
a0be328976
Revert "Remove buffer from BoxRoute ()" ()
This reverts commit 552d69e5d4.
2021-08-26 14:11:38 +00:00
David Pedersen
7b391d85c8
Version 0.2.2 ()
0.2.2 (24. August, 2021)

- **fixed:** Fix URI captures matching empty segments. This means requests with
  URI `/` will no longer be matched by `/:key` ([](https://github.com/tokio-rs/axum/pull/264))
- **fixed:** Remove needless trait bounds from `Router::boxed` ([](https://github.com/tokio-rs/axum/pull/264))
2021-08-26 06:57:07 +00:00
David Pedersen
552d69e5d4
Remove buffer from BoxRoute ()
Boxing a service normally means using `tower::util::BoxService`. That
doesn't implement `Clone` however so normally I had been combining it
with `Buffer` to get that.

But recently I discovered https://github.com/dtolnay/dyn-clone which
makes it possible to clone trait objects. So this adds a new internal
utility called `CloneBoxService` which replaces the previous
`BoxService` + `Buffer` combo in `BoxRoute`.

I'll investigate upstreaming that to tower. I think it makes sense there
since box + clone is quite a common need.
2021-08-26 06:34:53 +00:00
David Pedersen
20f6c3b509
Remove needless traits bounds from Router::boxed ()
Turns out these bounds weren't actually needed.

I was hoping it would speed up compile times but that isn't the case.
2021-08-26 08:24:21 +02:00
David Pedersen
0d2db387a8
Fix URI captures matching empty segments ()
It was never the intention that `/:key` should match `/`. This fixes
that.

Part of https://github.com/tokio-rs/axum/issues/259
2021-08-24 18:27:06 +00:00
Jonas Platte
ab207af060
Rename .route() / .nest() "description" to "path" () 2021-08-24 19:29:28 +02:00
David Pedersen
9a082a74b0
Version 0.2.1 ()
0.2.1 (24. August, 2021)

- **added:** Add `Redirect::to` constructor ([](https://github.com/tokio-rs/axum/pull/255))
- **added:** Document how to implement `IntoResponse` for custom error type ([](https://github.com/tokio-rs/axum/pull/258))
2021-08-24 12:53:57 +02:00
David Pedersen
3d4ef9dc32
Document how to implement IntoResponse for custom error type ()
Fixes https://github.com/tokio-rs/axum/issues/249
2021-08-24 12:42:10 +02:00
Jonas Platte
536b8ca4ec
Add Redirect::to constructor ()
The motivation for this is established in the issue it fixes.

Resolves 
2021-08-24 12:13:18 +02:00
programatik29
1a5f977896
Simplify tls-rustls example ()
## Motivation

Current `tls-rustls` example might be inconvenient for some people.

## Solution

Rename current example to `low-level-rustls` and add a high level example in its place.
2021-08-24 09:56:31 +02:00
bear
52ccb1bf42
Update StreamBody doc link () 2021-08-24 07:58:35 +02:00
Eduardo Canellas
1b5359add7
small changes to error handling example () 2021-08-24 07:42:13 +02:00
David Pedersen
02e61dfdd6
Version 0.2.0 ()
- Overall:
  - **fixed:** Overall compile time improvements. If you're having issues with compile time
    please file an issue! ([](https://github.com/tokio-rs/axum/pull/184)) ([](https://github.com/tokio-rs/axum/pull/198)) ([](https://github.com/tokio-rs/axum/pull/220))
  - **changed:** Remove `prelude`. Explicit imports are now required ([](https://github.com/tokio-rs/axum/pull/195))
- Routing:
  - **added:** Add dedicated `Router` to replace the `RoutingDsl` trait ([](https://github.com/tokio-rs/axum/pull/214))
  - **added:** Add `Router::or` for combining routes ([](https://github.com/tokio-rs/axum/pull/108))
  - **fixed:** Support matching different HTTP methods for the same route that aren't defined
    together. So `Router::new().route("/", get(...)).route("/", post(...))` now
    accepts both `GET` and `POST`. Previously only `POST` would be accepted ([](https://github.com/tokio-rs/axum/pull/224))
  - **fixed:** `get` routes will now also be called for `HEAD` requests but will always have
    the response body removed ([](https://github.com/tokio-rs/axum/pull/129))
  - **changed:** Replace `axum::route(...)` with `axum::Router::new().route(...)`. This means
    there is now only one way to create a new router. Same goes for
    `axum::routing::nest`. ([](https://github.com/tokio-rs/axum/pull/215))
  - **changed:** Implement `routing::MethodFilter` via [`bitflags`](https://crates.io/crates/bitflags) ([](https://github.com/tokio-rs/axum/pull/158))
  - **changed:** Move `handle_error` from `ServiceExt` to `service::OnMethod` ([](https://github.com/tokio-rs/axum/pull/160))

  With these changes this app using 0.1:

  ```rust
  use axum::{extract::Extension, prelude::*, routing::BoxRoute, AddExtensionLayer};

  let app = route("/", get(|| async { "hi" }))
      .nest("/api", api_routes())
      .layer(AddExtensionLayer::new(state));

  fn api_routes() -> BoxRoute<Body> {
      route(
          "/users",
          post(|Extension(state): Extension<State>| async { "hi from nested" }),
      )
      .boxed()
  }
  ```

  Becomes this in 0.2:

  ```rust
  use axum::{
      extract::Extension,
      handler::{get, post},
      routing::BoxRoute,
      Router,
  };

  let app = Router::new()
      .route("/", get(|| async { "hi" }))
      .nest("/api", api_routes());

  fn api_routes() -> Router<BoxRoute> {
      Router::new()
          .route(
              "/users",
              post(|Extension(state): Extension<State>| async { "hi from nested" }),
          )
          .boxed()
  }
  ```
- Extractors:
  - **added:** Make `FromRequest` default to being generic over `body::Body` ([](https://github.com/tokio-rs/axum/pull/146))
  - **added:** Implement `std::error::Error` for all rejections ([](https://github.com/tokio-rs/axum/pull/153))
  - **added:** Add `OriginalUri` for extracting original request URI in nested services ([](https://github.com/tokio-rs/axum/pull/197))
  - **added:** Implement `FromRequest` for `http::Extensions` ([](https://github.com/tokio-rs/axum/pull/169))
  - **added:** Make `RequestParts::{new, try_into_request}` public so extractors can be used outside axum ([](https://github.com/tokio-rs/axum/pull/194))
  - **added:** Implement `FromRequest` for `axum::body::Body` ([](https://github.com/tokio-rs/axum/pull/241))
  - **changed:** Removed `extract::UrlParams` and `extract::UrlParamsMap`. Use `extract::Path` instead ([](https://github.com/tokio-rs/axum/pull/154))
  - **changed:** `extractor_middleware` now requires `RequestBody: Default` ([](https://github.com/tokio-rs/axum/pull/167))
  - **changed:** Convert `RequestAlreadyExtracted` to an enum with each possible error variant ([](https://github.com/tokio-rs/axum/pull/167))
  - **changed:** `extract::BodyStream` is no longer generic over the request body ([](https://github.com/tokio-rs/axum/pull/234))
  - **changed:** `extract::Body` has been renamed to `extract::RawBody` to avoid conflicting with `body::Body` ([](https://github.com/tokio-rs/axum/pull/233))
  - **changed:** `RequestParts` changes ([](https://github.com/tokio-rs/axum/pull/153))
      - `method` new returns an `&http::Method`
      - `method_mut` new returns an `&mut http::Method`
      - `take_method` has been removed
      - `uri` new returns an `&http::Uri`
      - `uri_mut` new returns an `&mut http::Uri`
      - `take_uri` has been removed
  - **changed:** Remove several rejection types that were no longer used ([](https://github.com/tokio-rs/axum/pull/153)) ([](https://github.com/tokio-rs/axum/pull/154))
- Responses:
  - **added:** Add `Headers` for easily customizing headers on a response ([](https://github.com/tokio-rs/axum/pull/193))
  - **added:** Add `Redirect` response ([](https://github.com/tokio-rs/axum/pull/192))
  - **added:** Add `body::StreamBody` for easily responding with a stream of byte chunks ([](https://github.com/tokio-rs/axum/pull/237))
  - **changed:** Add associated `Body` and `BodyError` types to `IntoResponse`. This is
    required for returning responses with bodies other than `hyper::Body` from
    handlers. See the docs for advice on how to implement `IntoResponse` ([](https://github.com/tokio-rs/axum/pull/86))
  - **changed:** `tower::util::Either` no longer implements `IntoResponse` ([](https://github.com/tokio-rs/axum/pull/229))

  This `IntoResponse` from 0.1:
  ```rust
  use axum::{http::Response, prelude::*, response::IntoResponse};

  struct MyResponse;

  impl IntoResponse for MyResponse {
      fn into_response(self) -> Response<Body> {
          Response::new(Body::empty())
      }
  }
  ```

  Becomes this in 0.2:
  ```rust
  use axum::{body::Body, http::Response, response::IntoResponse};

  struct MyResponse;

  impl IntoResponse for MyResponse {
      type Body = Body;
      type BodyError = <Self::Body as axum::body::HttpBody>::Error;

      fn into_response(self) -> Response<Self::Body> {
          Response::new(Body::empty())
      }
  }
  ```
- SSE:
  - **added:** Add `response::sse::Sse`. This implements SSE using a response rather than a service ([](https://github.com/tokio-rs/axum/pull/98))
  - **changed:** Remove `axum::sse`. Its been replaced by `axum::response::sse` ([](https://github.com/tokio-rs/axum/pull/98))

  Handler using SSE in 0.1:
  ```rust
  use axum::{
      prelude::*,
      sse::{sse, Event},
  };
  use std::convert::Infallible;

  let app = route(
      "/",
      sse(|| async {
          let stream = futures::stream::iter(vec![Ok::<_, Infallible>(
              Event::default().data("hi there!"),
          )]);
          Ok::<_, Infallible>(stream)
      }),
  );
  ```

  Becomes this in 0.2:

  ```rust
  use axum::{
      handler::get,
      response::sse::{Event, Sse},
      Router,
  };
  use std::convert::Infallible;

  let app = Router::new().route(
      "/",
      get(|| async {
          let stream = futures::stream::iter(vec![Ok::<_, Infallible>(
              Event::default().data("hi there!"),
          )]);
          Sse::new(stream)
      }),
  );
  ```
- WebSockets:
  - **changed:** Change WebSocket API to use an extractor plus a response ([](https://github.com/tokio-rs/axum/pull/121))
  - **changed:** Make WebSocket `Message` an enum ([](https://github.com/tokio-rs/axum/pull/116))
  - **changed:** `WebSocket` now uses `Error` as its error type ([](https://github.com/tokio-rs/axum/pull/150))

  Handler using WebSockets in 0.1:

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

  let app = route(
      "/",
      ws(|socket: WebSocket| async move {
          // do stuff with socket
      }),
  );
  ```

  Becomes this in 0.2:

  ```rust
  use axum::{
      extract::ws::{WebSocket, WebSocketUpgrade},
      handler::get,
      Router,
  };

  let app = Router::new().route(
      "/",
      get(|ws: WebSocketUpgrade| async move {
          ws.on_upgrade(|socket: WebSocket| async move {
              // do stuff with socket
          })
      }),
  );
  ```
- Misc
  - **added:** Add default feature `tower-log` which exposes `tower`'s `log` feature. ([](https://github.com/tokio-rs/axum/pull/218))
  - **changed:** Replace `body::BoxStdError` with `axum::Error`, which supports downcasting ([](https://github.com/tokio-rs/axum/pull/150))
  - **changed:** `EmptyRouter` now requires the response body to implement `Send + Sync + 'static'` ([](https://github.com/tokio-rs/axum/pull/108))
  - **changed:** `Router::check_infallible` now returns a `CheckInfallible` service. This
    is to improve compile times ([](https://github.com/tokio-rs/axum/pull/198))
  - **changed:** `Router::into_make_service` now returns `routing::IntoMakeService` rather than
    `tower::make::Shared` ([](https://github.com/tokio-rs/axum/pull/229))
  - **changed:** All usage of `tower::BoxError` has been replaced with `axum::BoxError` ([](https://github.com/tokio-rs/axum/pull/229))
  - **changed:** Several response future types have been moved into dedicated
    `future` modules ([](https://github.com/tokio-rs/axum/pull/133))
  - **changed:** `EmptyRouter`, `ExtractorMiddleware`, `ExtractorMiddlewareLayer`,
    and `QueryStringMissing` no longer implement `Copy` ([](https://github.com/tokio-rs/axum/pull/132))
  - **changed:** `service::OnMethod`, `handler::OnMethod`, and `routing::Nested` have new response future types ([](https://github.com/tokio-rs/axum/pull/157))
2021-08-23 20:49:29 +02:00
David Pedersen
c2bfaf26d8 Removing prelude is a "changed" not a "fixed" 2021-08-23 18:42:51 +02:00
David Pedersen
0ab6ea6b6a Mention tower-log feature in docs 2021-08-23 18:40:18 +02:00
David Pedersen
cb6f5b95b3 Minor reordering of changelog 2021-08-23 18:40:07 +02:00
David Pedersen
d006b4f6f7 Remove notice about breaking changes in 0.2 from readme 2021-08-23 18:36:34 +02:00
David Pedersen
77f7b51d2f Update readme example to 0.2 2021-08-23 18:36:11 +02:00
David Pedersen
c8c8e6509b
Add upgrade examples to the changelog ()
Shows how to upgrade

- General routing
- SSE
- WebSockets
2021-08-23 18:24:08 +02:00