Basic handlers
A handler is any async function that implements theHandler trait:
Handler signatures
Handlers can take extractors as arguments and return any type that implementsIntoResponse:
Zero or more extractors
Extractors pull data from the request. They must implement
FromRequestParts or FromRequest.Extractors in handlers
Handlers can extract data from requests using extractors:The order of extractors matters. See Extractors for details.
Return types
Handlers can return various types:- Strings and static str
- Status codes
- JSON
- Result types
Error handling in handlers
UseResult types to handle errors:
Converting handlers to services
Handlers can be converted to Tower services:Applying middleware to handlers
You can apply middleware directly to individual handlers:Debugging handler errors
Next steps
Extractors
Learn how to extract data from requests
Responses
Explore different response types