package mantra.web
Response
CLASS
public class
Fluent HTTP response model supporting status codes, content types, and serialization to wire format.
🏗️ Constructor Summary
Constructor Signature
def __init__(self, status: Int, content_type: String, body: String)
⚙️ Method Summary
| Modifier & Return Type | Method Signature | Description |
|---|---|---|
Response |
static def ok(body: String) |
Creates an HTTP 200 OK response with the given body content. |
Response |
static def created(body: String) |
Creates an HTTP 201 Created response with the given body content. |
Response |
static def not_found(msg: String) |
Creates an HTTP 404 Not Found JSON error response. |
Response |
static def bad_request(msg: String) |
Creates an HTTP 400 Bad Request JSON error response. |
String |
pub def to_http_string() |
Serializes response status, headers, and body into HTTP wire format. |
🔍 Detailed Method Specifications
static def ok(body: String) -> Response
Creates an HTTP 200 OK response with the given body content.
static def created(body: String) -> Response
Creates an HTTP 201 Created response with the given body content.
static def not_found(msg: String) -> Response
Creates an HTTP 404 Not Found JSON error response.
static def bad_request(msg: String) -> Response
Creates an HTTP 400 Bad Request JSON error response.
pub def to_http_string() -> String
Serializes response status, headers, and body into HTTP wire format.
💡 Example Usage
response_example.mantra
let res_ok = Response.ok("{\"status\": \"success\"}")
let res_err = Response.not_found("User entity does not exist")
print(res_ok.to_http_string())