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 outputs ResponseJson. Inside function body the input json will be parsed to state object.
  • Return arbitrary json object. serde_json::Value can be a valid json object of any kind. Wrapping output around axum::Json as it implements IntoResponse 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 because IntoResponse trait is by default implemented for it.