Commit graph

31 commits

Author SHA1 Message Date
Lennart Melzer
368c3ee08f
Add IntoResponse impl to customize-extractor-error example (#2191) 2023-09-11 12:12:03 +00:00
tuhana
64c566cd1c
Fix typo on customize-extractor-error example (#2124) 2023-07-27 14:03:10 +00:00
David Pedersen
f9ea40bb44
Don't depend on axum-macros in examples (#2122) 2023-07-26 20:21:39 +02:00
David Pedersen
c97967252d Add serve function and remove Server re-export (#1868) 2023-04-21 17:45:31 +02:00
David Pedersen
6703f8634c Remove B type param: Follow ups (#1789)
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
Co-authored-by: Michael Scofield <mscofield0@tutanota.com>
2023-04-21 17:45:31 +02:00
David Pedersen
4e4c29175f Remove B type param (#1751)
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
Co-authored-by: Michael Scofield <mscofield0@tutanota.com>
2023-04-21 17:45:31 +02:00
Jonas Platte
dc480f7b0e
Re-integrate examples into the root workspace (#1466)
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2023-03-10 12:02:11 +01:00
David Pedersen
1dc4b44472
Use JsonRejection::{status, body_text} in customize extractor error example (#1790) 2023-02-25 15:02:02 +01:00
tottoto
6c133be5b7
Refactor initializing tracing-subscriber in examples (#1596)
* Refactor initializing tracing-subscriber

* Revert "Refactor initializing tracing-subscriber"

This reverts commit 0876260bf9 in favor of tracing_subscriber::registry.

* Use EnvFilter::try_from_default_env in chat example

* Use EnvFilter::try_from_default_env in examples
2022-11-30 10:46:19 +01:00
Jonas Platte
a7d8954178
Use RequestPartsExt more in docs / examples (#1445)
* Use RequestPartsExt more in docs / examples

* Remove unused import
2022-10-04 17:26:51 +00:00
Horu
a3c58a18ed
Fix typo in example (#1439) 2022-10-01 13:49:15 +00:00
David Pedersen
be624306f4
Only allow last extractor to mutate the request (#1272)
* Only allow last extractor to mutate the request

* Change `FromRequest` and add `FromRequestParts` trait (#1275)

* Add `Once`/`Mut` type parameter for `FromRequest` and `RequestParts`

* 🪄

* split traits

* `FromRequest` for tuples

* Remove `BodyAlreadyExtracted`

* don't need fully qualified path

* don't export `Once` and `Mut`

* remove temp tests

* depend on axum again

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

* Port `Handler` and most extractors (#1277)

* Port `Handler` and most extractors

* Put `M` inside `Handler` impls, not trait itself

* comment out tuples for now

* fix lints

* Reorder arguments to `Handler` (#1281)

I think `Request<B>, Arc<S>` is better since its consistent with
`FromRequest` and `FromRequestParts`.

* Port most things in axum-extra (#1282)

* Port `#[derive(TypedPath)]` and `#[debug_handler]` (#1283)

* port #[derive(TypedPath)]

* wip: #[debug_handler]

* fix #[debug_handler]

* don't need itertools

* also require `Send`

* update expected error

* support fully qualified `self`

* Implement FromRequest[Parts] for tuples (#1286)

* Port docs for axum and axum-core (#1285)

* Port axum-extra (#1287)

* Port axum-extra

* Update axum-core/Cargo.toml

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

* remove `impl FromRequest for Either*`

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

* New FromRequest[Parts] trait cleanup (#1288)

* Make private module truly private again

* Simplify tuple FromRequest implementation

* Port `#[derive(FromRequest)]` (#1289)

* fix tests

* fix docs

* revert examples

* fix docs link

* fix intra docs links

* Port examples (#1291)

* Document wrapping other extractors (#1292)

* axum-extra doesn't need to depend on axum-core (#1294)

Missed this in https://github.com/tokio-rs/axum/pull/1287

* Add `FromRequest` changes to changelogs (#1293)

* Update changelog

* Remove default type for `S` in `Handler`

* Clarify which types have default types for `S`

* Apply suggestions from code review

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

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

* remove unused import

* Rename `Mut` and `Once` (#1296)

* fix trybuild expected output

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-08-22 12:23:20 +02:00
David Pedersen
79f6aabd02 Make extractor field public in example 2022-08-19 22:38:46 +02:00
Altair Bueno
789f51ba1a
Extend custom rejection examples (#1276)
* examples: Created new `error-handling` example

* examples(error-handling): Add error codes and responses

* examples(error-handling): `custom_extractor`

* examples(error-handling): `derive_from_request`

* examples(error-handling): Using POST instead of GET

* examples(error-handling): Using `thiserror` for `derive_from_request`

* examples(error-handling): Using `snake-case` for routes

* revert(error-handling): Use `From` impl instead of `thiserror`

refs: 3533d96215

* examples(error-handling): Removed chrono

* examples: merged `error-handling` and `customize-extractor-error`

* examples(customize-extractor-error): Improved error codes

* examples(customize-extractor-error): rustfmt

* examples(customize-extractor-error): Removed `matched-path` feature

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

* examples(customize-extractor-error): added `publish=false` to `Cargo.toml`

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

* examples(customize-extractor-error): Fix env filter

* examples(customize-extractor-error): Added README

* examples(customize-extractor-error): Added `with_rejection` comments

* examples(customize-extractor-error): Added `custom_extractor` comments

* examples(customize-extractor-error):Typo on `with_rejection`

* examples(customize-extractor-error): Added `boilerplate` con to `custom_extractor`

* examples(customize-extractor-error): Added `derive_from_request` comments

* examples(customize-extractor-error): typo impossible

* examples(customize-extractor-error): typos

* examples(customize-extractor-error): replaced `extensions` with `extract`

* examples(customize-extractor-error): typo `from`

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

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-08-19 13:11:03 +00:00
David Pedersen
e7f1c88cd4
Always store state in an Arc (#1270)
* Add extension and state benchmarks

* wip

* Arc the state everywhere

* don't require `S: Clone`

* fix example
2022-08-17 20:08:24 +00:00
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
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
93251fa203
Bump MSRV to 1.56 and update to the 2021 edition (#1098) 2022-06-17 20:11:35 +02:00
David Pedersen
968ee44631
Sort dependencies in Cargo.tomls (#1076)
* sort dependencies

* check sorted deps on CI

* this should fail

* does caching matter?

* fix sorting
2022-06-10 08:59:17 +02:00
David Pedersen
1fe4558362
Move examples to separate workspace (#978)
* Move examples to separate workspace

* update commands to run examples

* remove debug
2022-04-29 18:53:41 +02:00
David Pedersen
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 <jplatte+git@posteo.de>

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-03-18 16:53:39 +01:00
Jonas Platte
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
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
David Pedersen
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
Jonas Platte
9c77ee0295
Use nightly clippy & rustfmt for more style checks (#487) 2021-11-09 11:53:57 +00:00
EdorianDark
513c5a694d
Update tracing-subscriber to 0.3 (#472)
Fixes #469
2021-11-06 14:50:23 +00:00
David Pedersen
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
David Pedersen
7692baf837
Reorganize method routers for handlers and services (#405)
* Re-organize method routing for handlers

* Re-organize method routing for services

* changelog
2021-10-24 20:05:16 +00:00
silvioprog
8ca5538405
Fix typo in main.rs (#381) 2021-10-12 18:20:27 +00:00
David Pedersen
ac291baaec
Fix dead code warnings (#373) 2021-10-07 16:49:57 +02:00
David Pedersen
f8154a088c
Add example showing up to customize extractor error (#356)
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