Commit Graph
168 Commits
Author SHA1 Message Date
a237edb7c3 Fix example-unix-domain-socket on non-unix platforms (#919)
* remove unused `axum`'s dependency:`tokio-util`

* fix `examples/todos`'s `async fn todos_index` iter_overeager_cloned

* Add docs to `/examples/async-graphql`, just like other xamples.

* remove `examples/async-graphql` unused dependencies `tracing-subscriber` and `trace`

* `examples/chat` deps `trace` and `tracing-subscriber` never be used. Add trace `debug` to `chat`

* remove `examples/print-request-response` unused dependency `axum-extra`

* remove `examples/prometheus-metrics` unused dependency `axum-extra`

* remove `examples/reverse-proxy` unused dependencies `tracing-subscriber` and `trace`

* `examples/chat` fmt fix

* fix `example-unix-domain-socket` compile error on not-unix platforms

Co-authored-by: zys864 <[email protected]>
Co-authored-by: zys864 <[email protected]>
2022-04-08 11:29:52 +02:00
Simon SellarandGitHub 59007d6111 Minor fixup of websocket example logging text. (#910) 2022-04-06 10:33:34 +00:00
David PedersenandGitHub 2270cf7b3e Add "stream to file" example (#903)
* Add "stream to file" example

* add title tag
2022-04-03 12:28:29 +02:00
David PedersenandGitHub 21552fe434 Remove bound from into_make_service_with_connect_info (#892)
Fixes #859
2022-03-31 16:49:49 +00:00
3084dc10ca Accept &str for Redirect (#889)
* Accept &str for Redirect

* Fix doc example

* fix more docs examples

* update changelog

* fix changelog label

Co-authored-by: David Pedersen <[email protected]>
2022-03-31 10:03:06 +02:00
437fe5b931 Make status codes for JsonRejection more precise (#868)
* Fix status codes for `JsonRejection` rejections

Fixes #865

* Apply suggestions from code review

Co-authored-by: Jonas Platte <[email protected]>

Co-authored-by: Jonas Platte <[email protected]>
2022-03-18 16:53:39 +01:00
David PedersenandGitHub 33ee55e52c Add example for consuming request body in middleware and extractor (#861) 2022-03-18 15:41:38 +00:00
Jonas PlatteandGitHub 79b94b9bd6 Replace set_var usage in examples (#829)
* examples: Fix inconsistent toml formatting

* examples: Replace set_var usage
2022-03-06 12:37:00 +01:00
Max BrucknerandGitHub 99fbd3d32c Add note about order of extractors in the reverse-proxy example (#821) 2022-03-03 22:33:33 +01:00
zys864andGitHub 768d8a8218 Fix minor issues in some examples (#806)
* remove unused `axum`'s dependency:`tokio-util`

* fix `examples/todos`'s `async fn todos_index` iter_overeager_cloned

* Add docs to `/examples/async-graphql`, just like other xamples.

* remove `examples/async-graphql` unused dependencies `tracing-subscriber` and `trace`

* `examples/chat` deps `trace` and `tracing-subscriber` never be used. Add trace `debug` to `chat`

* remove `examples/print-request-response` unused dependency `axum-extra`

* remove `examples/prometheus-metrics` unused dependency `axum-extra`

* remove `examples/reverse-proxy` unused dependencies `tracing-subscriber` and `trace`

* `examples/chat` fmt fix
2022-03-01 09:30:09 +00:00
David PedersenandGitHub a2b568c7c1 Implement tower::Layer for Extension (#801)
* Implement `tower::Layer` for `Extension`

* changelog
2022-03-01 00:39:22 +01:00
f12ab072c5 Add IntoResponseParts (#797)
* Add `IntoResponseParts`

* docs

* Add test

* don't allow overriding body or response

* macroify impls

* re-order things a bit

* Fix tests

* Also allow overriding version

* Move things into separate modules

* docs

* clean up

* fix trybuild test

* remove churn

* simplify buliding response

* fixup test

* fix docs typo

* Use `HeaderValue::from_static`, might be faster

* Bring back `impl IntoResponse` in example

* Remove blanket impl to improve error message

* don't need to set `content-type`

* Apply suggestions from code review

Co-authored-by: Jonas Platte <[email protected]>

* changelog

Co-authored-by: Jonas Platte <[email protected]>
2022-02-28 23:04:33 +00:00
zys864andGitHub cb168b96fe fix examples/todos's async fn todos_index iter_overeager_cloned (#794)
* remove unused `axum`'s dependency:`tokio-util`

* fix `examples/todos`'s `async fn todos_index` iter_overeager_cloned
2022-02-25 15:29:23 +01:00
frobiacandGitHub 8c0926ee5b examples(jwt): Claims.exp represents a UTC timestamp (#760)
For the example to work, it should be an epoch value in the future.

See https://github.com/Keats/jsonwebtoken/blob/d8a33def00a61bab12aa5e94ff76d3043d4d474e/README.md?plain=1#L61
2022-02-15 21:43:31 +00:00
David PedersenandGitHub 409a6651f5 Update dependencies (#753) 2022-02-12 17:16:14 +00:00
EvgeniiandGitHub 0c16ce7649 fix: typo in a comment in a sqlx-postgres example (#744) 2022-02-04 08:14:34 +01:00
a04fc42d75 Rework middleware docs (#732)
* rework middleware docs

* Apply suggestions from code review

Co-authored-by: Jonas Platte <[email protected]>

Co-authored-by: Jonas Platte <[email protected]>
2022-01-30 20:09:18 +01:00
YuKun LiuandGitHub c0473f2b6f Expand WebSocket example to match on Message (#723) 2022-01-25 15:31:33 +00:00
FlakMandGitHub 32c9ab3c56 Add sqlx example with migrations (#722)
* Add sqlx example with migrations

Simple use case for sqlx based on tokio postgres example.
Sqlite database is created on execution in ./target directory
and migrations are then run against it.

* sqlx example uses postgres instead of sqlite3

Also removed migrations and database creation code.
2022-01-25 16:20:00 +01:00
David PedersenandGitHub 9004a14302 Move middleware::from_fn into axum (#719)
* Move `middleware::from_fn` into axum

* changelog

* fix feature

* Rephrase changelog a bit
2022-01-25 10:19:06 +01:00
David Pedersen 184ea656c0 Change HeaderMap extractor to clone the headers (#698)
* Change `HeaderMap` extractor to clone the headers

* fix docs

* changelog

* inline variable

* also add changelog item to axum

* don't list types from axum in axum-core's changelog

* document that `HeaderMap::from_request` clones the headers

* fix typo

* a few more typos
2022-01-23 18:01:52 +01:00
Nick AshleyandDavid Pedersen 9b4232b786 Replace public use of mime crate with &str (#642)
Replaces `Field::content_type`'s return type with `&str`.
This is a breaking change.

Closes #637
2022-01-23 18:01:52 +01:00
Nick AshleyandGitHub 007a0e85f2 Use 308 instead of 301 for trailing slash redirects (#682)
* Use 308 status instead of 301 when redirecting

For redirects resulting from requests to paths with a trailing slash,
use 308 instead of 301 to prevent non-GET requests (POST, PUT, etc) from
being changed to GET.

For example, (assuming a route for /path is defined)...
  - Old behavior results in:
  POST /path/ -> GET /path

  - New behavior results in:
  POST /path/ -> POST /path

Fixes #681

* Add deprecation notice to found()

Deprecates found() due to its use of HTTP 302

* rustfmt

* Use dedicated redirect method

Use Redirect::permanent instead of re-implementing its functionality

* Remove deprecated method from example

Replace usages of Redirect:found with Redirect::to and Redirect::temporary as appropriate

* Fix panic in oauth example

Previously the example would panic if a request was made without the
`Cookie` header. Now the user is redirected to the login page as
expected.

* Update CHANGELOG

* Revert pub TypedheaderRejection fields

* Fix clippy lint

* cargo fmt

* Fix CHANGELOG link

* Adhere to implicit line length limit
2022-01-12 15:14:06 +01:00
David PedersenandGitHub 6d24a8695f Add SSE tests (#652)
* Add SSE tests

* Simplify keep alive test a bit

* More robust keep-alive tests

* rename a bit
2022-01-03 18:48:50 +01:00
Jonas PlatteandGitHub 616a43aaa3 Simplify graceful shutdown (#673) 2021-12-28 16:23:07 +01:00
David PedersenandGitHub 5698fb8be9 Add metrics example (#671) 2021-12-28 15:58:48 +01:00
Jonas PlatteandGitHub 0a399ed0fa A few small refactorings (#655)
* Simplify json content-type check

* Import HeaderMap from http instead of from headers

The headers crate is an optional dependency and its HeaderMap re-export
is `#[doc(hidden)]`.

* Use headers re-export in axum in examples
2021-12-27 14:02:38 +01:00
David PedersenandGitHub f4716084a7 Add middleware::from_fn for creating middleware from async fns (#656)
* Add `middleware::from_fn` for creating middleware from async fns

* More trait impls for `Next`

* Make `Next::run` consume `self`

* Use `.router_layer` in example, since middleware returns early

* Actually `Next` probably shouldn't impl `Clone` and `Service`

Has implications for backpressure and stuff

* Simplify `print-request-response` example

* Address review feedback

* add changelog link
2021-12-27 14:01:26 +01:00
3841ef44d5 Fix session cookie example (#638)
* refactor: refine session cookie example

* refactor: refine session_cookie extraction

* refactor: avoid to_owned()

* chore: refine debug log

Co-authored-by: 荒野無燈 <[email protected]>
2021-12-22 15:27:13 +01:00
David PedersenandGitHub ba42783df2 Example for defining routes and handlers close together (#621) 2021-12-12 23:54:18 +01:00
David PedersenandGitHub ecf3359980 Fix misc warnings from CI (#620) 2021-12-12 17:21:29 +01:00
Kai JewsonandGitHub 9ed18d92cf Use AtomicU32 in RouteId (#616) 2021-12-12 14:19:30 +00:00
Kai JewsonandGitHub dfb06e721c Introduce Response type alias as a shorthand for Response<BoxBody> (#590)
* Introduce `Response` type alias as a shorthand

* Don't re-export `Response` at the crate root
2021-12-05 19:16:46 +01:00
David PedersenandGitHub 3ec680cce7 Provide more data in Path deserialization error (#574)
* Provide more error in `Path` deserialization error

* Rename

* Add error kind for deserializing sequences

* Rename

* Fix wrong docs

* Rename `MissingRouteParams`

* Rename error to have more consistency

* Rename internal error

* Update changelog

* One last renaming, for now

* Add tests

* Tweak changelog a bit
2021-12-02 08:51:29 +01:00
David PedersenandGitHub 66c5142d0c Update tower-http (#581)
Updates to 0.2 which was just published.
2021-12-01 20:14:25 +00:00
David PedersenandGitHub 254d8fde17 Move FromRequest and IntoResponse into new axum-core crate (#564)
* Move `IntoResponse` to axum-core

* Move `FromRequest` to axum-core

* some clean up

* Remove hyper dependency from axum-core

* Fix docs reference

* Use default

* Update changelog

* Remove mention of default type
2021-11-30 13:46:13 +00:00
Kai JewsonandGitHub 2b6dba49cb Remove the associated Body type on IntoResponse (#571) 2021-11-28 18:52:18 +01:00
Pure WhiteandGitHub 5a5800c1ae feat: default to charset=utf-8 for text content type (#554)
* feat: default to charset=utf-8 for text content type

* added changelog && fix comment

* fix workflow
2021-11-25 08:31:30 +00:00
David PedersenandGitHub 9a410371a6 Move axum-handle-error-extract into axum (#534)
* Move `axum-handle-error-extract` into axum

With 0.4 underway we can now nuke `axum-handle-error-extract` and move
its code directly into axum.

So this replaces the old `HandleErrorLayer` with one that supports async
functions and extractors.

* changelog

* fix CI
2021-11-17 19:09:58 +00:00
David PedersenandGitHub a317072467 Rename box_body to body (#533)
Probably would have been easier to merge this change directly into
`main` first and the backport it to `v0.3.x` but here we are :P

Fixes #528
2021-11-17 12:59:29 +00:00
David PedersenandGitHub 2bd0310463 New method router (#521)
* Empty crate

* basic setup

* Support `HEAD`

* Add remaining methods

* Impl Debug

* Add `MethodRouter::merge`

* WIP

* Support same route with different methods in different calls

* Update changelog

* Bring back `any` and `any_service`

* Address review feedback
2021-11-16 20:49:07 +01:00
David PedersenandGitHub 20fabd87e9 Add CORS example (#512) 2021-11-13 22:18:14 +01:00
Eray KaratayandGitHub 2507463706 update tls-rustls example (#494) 2021-11-10 15:07:09 +01:00
ImbolcandGitHub 2ee66e812f FromStr based empty_string_as_none implementation (#486) 2021-11-09 13:05:31 +01:00
Jonas PlatteandGitHub 9c77ee0295 Use nightly clippy & rustfmt for more style checks (#487) 2021-11-09 11:53:57 +00:00
EdorianDarkandGitHub 513c5a694d Update tracing-subscriber to 0.3 (#472)
Fixes #469
2021-11-06 14:50:23 +00:00
Eray KaratayandGitHub 394ba31385 update low-level-rustls example (#465) 2021-11-05 12:02:58 +01:00
David Pedersen 0be0ea6763 Actually run the routing tests 🤦 2021-11-04 12:48:37 +01:00
david-perezandGitHub 071a1b26e6 Fix typos (#461) 2021-11-03 19:03:46 +00:00
David PedersenandGitHub ba4d8a2357 Move axum crate into workspace subfolder (#458)
* Move axum crate into workspace subfolder

Over time I imagine we're gonna have other crates in this repo that
provide utilities or integrations for axum. This prepares for that by
moving the main axum crate into its own folder.

The README situation is a bit annoying because we want `./README.md`
for viewing the repo on github but `axum/README.md` for crates.io. For
now I've just copy/pasted it and added CI step to make sure they're
identical.

* update changelog link

* Add licenses to all examples

* is this how you install `diff`?

* or maybe this is how?

* fix readme links

* like this?

* fix cargo-deny step

* Try making root readme a symlink

* remove compare readme step

not needed since readme in repo root is now a symlink

* Revert "Add licenses to all examples"

This reverts commit ab321b7fb9.
2021-11-03 12:38:48 +01:00