NoContent response type returns a 204 No Content status code, indicating that the request succeeded but there’s no content to return.
Basic usage
ReturnNoContent from handlers that perform an action but have nothing to return:
When to use NoContent
DELETE operations
The most common use case is successful DELETE requests:examples/todos/src/main.rs:146-151.
PUT operations with no response body
When updating a resource without returning the updated data:Successful operations with no data
Any operation that succeeds but has nothing to return:How it works
Type definition
axum/src/response/mod.rs:78.
IntoResponse implementation
TheNoContent type simply converts to a 204 No Content status code:
axum/src/response/mod.rs:80-84.
Comparison with unit type ()
The unit type
() returns 200 OK with an empty body, while NoContent returns 204 No Content.Using () returns 200 OK
Using NoContent returns 204 No Content
When to choose which
- Use
NoContent(204): When the operation succeeded and there’s intentionally no content (DELETE, some PUTs) - Use
()(200): When you want a default successful response (less common) - Use
StatusCode::NO_CONTENT: When you need more control or want to return it conditionally
Response fields
Always
204 No ContentThe response body is always empty
Common patterns
Using with Result for error handling
Conditional response with status codes
Using StatusCode directly
You can also useStatusCode::NO_CONTENT directly:
NoContent is more self-documenting, while StatusCode::NO_CONTENT gives you more flexibility for conditional logic.
See also
- StatusCode for other HTTP status codes
- IntoResponse trait for custom response types
- Response tuples for combining status codes with headers