Expand description
Response helpers for maximum simplicity
These functions provide one-liner response creation, making elif the easiest HTTP framework in Rust.
§Examples
use elif_http::response::{json, json_status, redirect, html};
use elif_http::{HttpResult, ElifResponse, ElifStatusCode};
// Simple one-liners
async fn get_users() -> HttpResult<ElifResponse> {
let users = vec!["Alice", "Bob"];
Ok(json(&users)) // Simple JSON response
}
async fn create_user() -> HttpResult<ElifResponse> {
let user_data = serde_json::json!({"name": "Alice"});
Ok(json_status(&user_data, ElifStatusCode::CREATED))
}
Functions§
- accepted
- Create an accepted response (202) with optional data
- bad_
request - Create a bad request response (400) with error message
- created
- Create a created response (201) with JSON data
- forbidden
- Create a forbidden response (403) with error message
- html
- Create an HTML response
- json
- Create a JSON response with 200 OK status
- json_
status - Create a JSON response with custom status code
- json_
with_ headers - Create a JSON response with headers
- no_
content - Create a no content response (204)
- not_
found - Create a not found response (404) with error message
- redirect
- Create a temporary redirect response (302)
- redirect_
permanent - Create a permanent redirect response (301)
- server_
error - Create an internal server error response (500) with error message
- text
- Create a plain text response
- unauthorized
- Create an unauthorized response (401) with error message
- validation_
error - Create a validation error response (422) with field errors