Commit graph

829 commits

Author SHA1 Message Date
David Pedersen
423308de3c
Add type safe state extractor (#1155)
* begin threading the state through

* Pass state to extractors

* make state extractor work

* make sure nesting with different states work

* impl Service for MethodRouter<()>

* Fix some of axum-macro's tests

* Implement more traits for `State`

* Update examples to use `State`

* consistent naming of request body param

* swap type params

* Default the state param to ()

* fix docs references

* Docs and handler state refactoring

* docs clean ups

* more consistent naming

* when does MethodRouter implement Service?

* add missing docs

* use `Router`'s default state type param

* changelog

* don't use default type param for FromRequest and RequestParts

probably safer for library authors so you don't accidentally forget

* fix examples

* minor docs tweaks

* clarify how to convert handlers into services

* group methods in one impl block

* make sure merged `MethodRouter`s can access state

* fix docs link

* test merge with same state type

* Document how to access state from middleware

* Port cookie extractors to use state to extract keys (#1250)

* Updates ECOSYSTEM with a new sample project (#1252)

* Avoid unhelpful compiler suggestion (#1251)

* fix docs typo

* document how library authors should access state

* Add `RequestParts::with_state`

* fix example

* apply suggestions from review

* add relevant changes to axum-extra and axum-core changelogs

* Add `route_service_with_tsr`

* fix trybuild expectations

* make sure `SpaRouter` works with routers that have state

* Change order of type params on FromRequest and RequestParts

* reverse order of `RequestParts::with_state` args to match type params

* Add `FromRef` trait (#1268)

* Add `FromRef` trait

* Remove unnecessary type params

* format

* fix docs link

* format examples

* Avoid unnecessary `MethodRouter`

* apply suggestions from review

Co-authored-by: Dani Pardo <dani.pardo@inmensys.com>
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-08-17 15:13:31 +00:00
David Pedersen
90dbd52ee4
Fix lint warnings (#1267) 2022-08-17 09:41:52 +00:00
David Pedersen
f2243c4db0
Make WithRejection::into_inner public (#1266) 2022-08-17 08:59:16 +00:00
David Pedersen
e22f6f9d2b
Add Either{2..8} to axum-extra (#1263)
* Add `Either{2..8}`

* Apply suggestions from code review

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

* Either2 => Either

* Update axum-extra/src/either.rs

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-08-17 08:57:19 +00:00
Altair Bueno
fb21561616
Add WithRejection (#1262)
* new(axum-extra): Added `WithRejection` base impl

Based on @jplatte's version (https://github.com/tokio-rs/axum/issues/1116#issuecomment-1215048273), with slight changes

- Using `From<E::Rejection>` to define the trait bound on a more concise way
- Renamed variables to something more meaningfull

* revert(axum-extra): Removed `with_rejection` feat

* ref(axum-extra): Replaced `match` with `?`

* tests(axum-extra): Added test for `WithRejection`

* examples: Replaced custom `Json` extractor with `WithRejection`

* docs(axum-extra): Added doc to `WithRejection`

* fmt(cargo-check): removed whitespaces

* fmt(customize-extractor-error): missing fmt

* docs(axum-extra): doctest includes `Handler` test

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>

* docs(axum-extra):` _ `-> `rejection`

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>

* docs(axum-extra): fixed suggestions

* fix(axum-extra): `WithRejection` manual trait impl

* revert(customize-extractor-error): Undo example changes

refs: d878eede18 , f9200bf4b9

* example(customize-extractor-error): Added reference to `WithRejection`

* docs(axum-extra): Removed `customize-extractor-error` reference

* fmt(axum-extra): cargo fmt

* docs(axum-extra): Added `WithRejection` to CHANGELOG.md

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-08-17 07:59:25 +00:00
David Pedersen
01630cfef6
Add sync constructors to CookieJar, SignedCookieJar, and PrivateCookieJar (#1264)
* Add sync constructors to `CookieJar`, `SignedCookieJar`, and `PrivateCookieJar`

* Move to constructor

* use `RequestParts::extract`
2022-08-16 15:42:01 +02:00
David Pedersen
fb32fcc07c Add protobuf extractor and response to changelog 2022-08-15 15:57:07 +02:00
David Pedersen
ac7037d282
Support using a different rejection for #[derive(FromRequest)] (#1256) 2022-08-12 16:05:27 +00:00
kkocdko
a8e80bcb97
Improve performance in low-level-rustls example (#1254) 2022-08-12 11:57:59 +00:00
Altair Bueno
90a2e04e9d
docs: Include axum-template on ECOSYSTEM.md (#1249) 2022-08-12 12:09:13 +02:00
Jonas Platte
7795e649f6
Avoid unhelpful compiler suggestion (#1251) 2022-08-12 10:06:38 +00:00
Dani Pardo
e1223935ca
Updates ECOSYSTEM with a new sample project (#1252) 2022-08-12 12:02:52 +02:00
David Pedersen
6cd356690d
Annotate panicking functions with #[track_caller] (#1248) 2022-08-11 12:45:42 +02:00
David Pedersen
50a4be999d
Update matchit and fix nesting inconsistencies (#1086)
* Break `Router::nest` into `nest` and `nest_service` methods

* fix doc tests

* update docs

* fix

* Only accept `Router` in `Resource::{nest, nest_collection}`

* update changelog

* fix docs

* fix `MatchedPath` with `Router`s nested with `nest_service`

* Apply suggestions from code review

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

* adjust docs for fallbacks

* Always nest services as opaque

* fix old docs reference

* more tests for `MatchedPath` with nested handlers

* minor clean up

* use identifier captures in format strings

* Apply suggestions from code review

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

* fix test

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-08-11 10:17:08 +00:00
David Pedersen
0090d007c0 Fix benchmark filtering 2022-08-11 11:12:04 +02:00
David Pedersen
9e50bf16fb
Add initial benchmarks (#1243)
* Add initial benchmarks

* improve error message if rewrk isn't installed

* what env vars does github ci have?

* run benchmarks for a bit on ci

* debug error

* ignore args on ci

* actually also locally

* apply review suggestions
2022-08-11 08:52:23 +00:00
Filip Kieres
7faf059234
Document browsers ignoring SSE events without data fields (#1242) (#1214) 2022-08-10 17:14:42 +02:00
David Pedersen
c72ee6eca9
Document browsers ignoring SSE events without data fields (#1242)
* Document browsers ignoring SSE events without data fields

* only add note on `Event::data`
2022-08-10 10:40:31 +00:00
David Pedersen
9b44654c86
Add "Ordering" link to middleware table of contents (#1241)
Seems I forgot to add it.
2022-08-10 12:34:05 +02:00
David Pedersen
e79820dbc4
Support chaining handlers with one.or(two).or(three) (#1170)
* WIP: Handler fallbacks

* Docs

* box futures a bit less

* changelog
2022-08-10 10:09:08 +00:00
Jonas Platte
7cbb7cf135
Use new Cargo features to avoid implicit features for optional dependencies (#1239)
* Fix changelog entry for MSRV change in axum-extra 0.3.5

* Bump MSRV to 1.60 for axum, axum-extra, axum-macros

* Use new Cargo features to avoid implicit features for optional dependencies
2022-08-09 18:43:02 +02:00
David Pedersen
d9ef24c5ff
Replace async-graphql with link to async-graphql's own examples (#1234)
* Replace async-graphql with link to async-graphql's own examples

* exclude async-graphql directory

* does this fix it?

* apparently this needs to be sorted as well

* Update .github/workflows/CI.yml

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-08-09 14:56:50 +00:00
Mark Tuddenham
ad7c8c5cdb
docs: use local variable in closure (#1232)
The "Using closure captures for shared state" example creates two clones
when only one is needed.
2022-08-09 16:23:16 +02:00
Max Countryman
95c6621db9
Improve workspace caching on CI (#1229)
* improve workspace caching

This improves workspace caching performance by using the workspace parameter of rust-cache@v2.

* apply the same technique here as well
2022-08-09 15:18:10 +02:00
Abdulla Abdurakhmanov
79a0a54bc9
Updated ECOSYSTEM with axum-streams reference (#1213) 2022-07-31 14:47:51 +00:00
Jas
f7860b6f00
Update ECOSYSTEM.md (#1212) 2022-07-31 07:13:09 +00:00
Jonas Platte
f0f60681ef
Fix intra-doc links on docs.rs (#1205)
* Use version 2 of Cargo's feature resolver

* Increase minimum version of tungstenite

Tungstenite 0.17.1 has a higher MSRV, and there should be no reason to
use it over 0.17.2.

* Clean up and fix MSRV CI job

* Fix some intra-doc links not resolving correctly on docs.rs

* Bump minimum version of tower

… to avoid dependencies with a broken minimum-versions chain.
2022-07-28 19:14:31 +02:00
Jonas Platte
141198ce19
Declare MSRV in Cargo manifests, not .clippy.toml (#1206) 2022-07-28 15:31:47 +02:00
Jonas Platte
e6fb53fd68
Fix a typo in axum_extra::extract::Query docs (#1201) 2022-07-27 16:32:21 +02:00
Péter Leéh
6ff1c2111e
Fix comment typos in stream-to-file example (#1200) 2022-07-27 11:10:00 +00:00
jord&
d7f2c140bc
Add rgit to ECOSYSTEM.md (#1197) 2022-07-27 03:39:09 +00:00
Lex Cao
3c0778b16d
Add an example for head request (#1189)
As #84 add get-head request, adding an example.
2022-07-26 20:19:03 +02:00
Ryan Fowler
7e7a2f2058
Create BytesMut for Json with initial capacity (#1196)
* Create BytesMut for Json with initial capacity

* Add a comment explaining BytesMut initial capacity

* Update link to serde_json::to_vec function to docs.rs
2022-07-26 16:45:58 +02:00
David Pedersen
3bcc8fb07d fix typo in CI.yml 2022-07-26 14:03:35 +02:00
David Pedersen
10ab8c7aba
Add missing cfg to axum_extra::extract::Form (#1194) 2022-07-26 00:25:45 +02:00
David Pedersen
234c8ccb13
Improve build times by generating less IR (#1192)
* example

* `MethodRouter::merge`

* `set_content_length` and `set_allow_header`

* `MethodRouter::on_service_boxed_response_body`

* `Router::route`

* `MethodRouter::merge` again

* `MethodRouter::on_service_boxed_response_body`

* `Router::call_route`

* `MethodRouter::{layer, route_layer}`

* revert example

* fix test

* move function to method on `AllowHeader`
2022-07-25 18:06:37 +00:00
Marek Kuskowski
1ace8554ce
Add ws example showing how to pass data to callback (#1185) 2022-07-23 16:27:36 +00:00
Sugih Jamin
4558671a0b
Redirect HTTP to HTTPS in tls-rustls example (#1166) 2022-07-23 10:23:40 +02:00
Johannes Henninger
bb309319ff
Fix typo in ECOSYSTEM.md (#1183) 2022-07-22 12:20:34 +02:00
Carlos Armando Marcano Vargas
216c89e44c
Add link to Axum tutorial (#1181) 2022-07-21 20:56:33 +00:00
Kartavya Vashishtha
cf09f62a1a
Add example for multiple listen addrs (#1179) 2022-07-20 18:33:12 +00:00
Jonas Platte
a3cf025d54
Serialize Json<T> to Bytes instead of Vec<u8> in IntoResponse (#1178) 2022-07-20 16:32:08 +00:00
azzamsa
a3eaa332e4
test: use ready() and call() to avoid using clone() (#1176) 2022-07-20 12:19:15 +00:00
David Pedersen
b243e171fd
Accept S::Response: IntoResponse everywhere (#1165) 2022-07-19 18:55:15 +02:00
LingDu
643909af6d
Add axum-admin to ECOSYSTEM.md (#1173)
* Update ECOSYSTEM.md

add axum_admin

* Update ECOSYSTEM.md

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-07-19 18:04:57 +02:00
Allan
928d60fbba
Fix two comment typos (#1172) 2022-07-18 17:16:38 +00:00
SzudemJ
73041c8988
Avoid exposure of type names by QueryRejection (#1171) 2022-07-18 13:43:18 +00:00
David Pedersen
329bd5f9b4
Support any middleware response that implements IntoResponse (#1152)
* Support any middleware response that implements `IntoResponse`

* Require `Infallible` for middleware added with `Handler::layer`
2022-07-13 08:38:19 +00:00
Oskar
0a7fdd0b05
add HomeDisk to Project showcase (#1156) 2022-07-11 19:22:01 +02:00
David Pedersen
92dbbd3182
Return rejection if WebSocket request couldn't be upgraded (#1135)
* Return rejection if `WebSocket` request couldn't be upgraded

* make rejection about connection upgrades

* changelog links
2022-07-11 14:33:55 +02:00