Module 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§

append_to_string
Provide request json in form of RequestJson and outputs ResponseJson. Inside function body the input json will be parsed to state object.
get_country
Function calls external RestCountries API and extracts information about given country. Function expects query parameter in form of ?name=<country_name>.
get_json
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.
get_json_counter
Return how many times get_json has been called. This introduces shared state implemented with Arc and Mutex.
get_random_number
Function generates single random number and returns it as String. String is viable output because IntoResponse trait is by default implemented for it.