Module example_webserver_rs::handlers
source · Expand description
In axum a “handler” is an async function that accepts zero or more “extractors” as arguments and returns something that can be converted into a response.
Functions§
- Provide request json in form of
RequestJson
and outputsResponseJson
. Inside function body the input json will be parsed tostate
object. - Return arbitrary json object.
serde_json::Value
can be a valid json object of any kind. Wrapping output aroundaxum::Json
as it implementsIntoResponse
trait. - Return how many times
get_json
has been called. This introduces shared state implemented with Arc and Mutex. - Function generates single random number and returns it as
String
.String
is viable output becauseIntoResponse
trait is by default implemented for it.