Module helpers

Module helpers 

Source
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