Commit Graph
25 Commits
Author SHA1 Message Date
Weipeng HongandGitHub ef1448a3f5 Use env!("CARGO_CRATE_NAME") in the example to simplify the tracing setup code (#2884) 2024-08-24 08:36:08 +02:00
Joel UckelmanandGitHub 2e963cea9d Add a use of route_service with ServeFile to the static-file-server example (#2361) 2023-11-27 15:49:54 +01:00
David Pedersen c97967252d Add serve function and remove Server re-export (#1868) 2023-04-21 17:45:31 +02:00
6703f8634c Remove B type param: Follow ups (#1789)
Co-authored-by: Jonas Platte <[email protected]>
Co-authored-by: Michael Scofield <[email protected]>
2023-04-21 17:45:31 +02:00
4e4c29175f Remove B type param (#1751)
Co-authored-by: Jonas Platte <[email protected]>
Co-authored-by: Michael Scofield <[email protected]>
2023-04-21 17:45:31 +02:00
dc480f7b0e Re-integrate examples into the root workspace (#1466)
Co-authored-by: David Pedersen <[email protected]>
2023-03-10 12:02:11 +01:00
2c1dde7c07 Fix static-file-server example instructions (#1832)
Co-authored-by: MoisesPotato <[email protected]>
2023-03-10 09:51:22 +01:00
David PedersenandGitHub 27f05ad32e Remove SpaRouter (#1784) 2023-02-25 11:05:23 +01:00
David PedersenandGitHub f726f16b6d Update to tower-http 0.4 (#1783) 2023-02-24 20:51:30 +00:00
tottotoandGitHub 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
8d6313afa0 Add example of static-file-server using serve dir with handler as service (#1501)
* add example of static-file-seriver using serve dit with handler as service

* update handle return type in example

Co-authored-by: David Pedersen <[email protected]>

* cargo fmt fix

* change error mapping

Co-authored-by: David Pedersen <[email protected]>
2022-11-08 20:40:20 +01:00
David PedersenandGitHub 199a7a66b8 Expand static file serving example (#1471) 2022-10-11 07:42:48 +00:00
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 <[email protected]>
Co-authored-by: Jonas Platte <[email protected]>
2022-08-17 15:13:31 +00:00
David PedersenandGitHub 7774cfd1f7 Update static file server example (#1011) 2022-05-08 19:52:34 +00:00
David PedersenandGitHub 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
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
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 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 9465128f3e Rework docs (#437)
This reworks axum's docs in an attempt to make things easier to find. Previously I wasn't a fan of those docs for the same topic were spread across the root module docs and more specific places like types and methods.

This changes it such that the root module docs only gives a high level introduction to a topic, perhaps with a small example, and then link to other places where all the details are. This means `Router` is now the single place to learn about routing, and etc for the topics like handlers and error handling.
2021-11-01 21:13:37 +00:00
David PedersenandGitHub 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
David PedersenandGitHub f10508db0b Revamp error handling model (#402)
* Revamp error handling model

* changelog improvements and typo fixes

* Fix a few more Infallible bounds

* minor docs fixes
2021-10-24 17:33:03 +00:00
Andrei ZolkinandGitHub 9df57e6ff2 Migrate all examples to use std::env::var_os (#312) 2021-09-12 17:39:43 +02:00
David PedersenandGitHub ca4d9a2bb9 Replace route with Router::new().route() (#215)
This way there is now only one way to create a router:

```rust
use axum::{Router, handler::get};

let app = Router::new()
    .route("/foo", get(handler))
    .route("/foo", get(handler));
```

`nest` was changed in the same way:

```rust
use axum::Router;

let app = Router::new().nest("/foo", service);
```
2021-08-19 22:37:48 +02:00
David PedersenandGitHub 97b53768ba Replace RoutingDsl trait with Router type (#214)
* Remove `RoutingDsl`

* Fix typo
2021-08-19 21:24:32 +02:00
David PedersenandGitHub 6c9651c14a Move all examples to their own crates (#201)
This makes it much clearer which dependencies each example has.
2021-08-18 00:49:01 +02:00