Module format

Source
Expand description

This module contains utility functions for generating HTTP responses that are commonly used in web applications. These functions simplify the process of creating responses with various data types.

§Example:

This example illustrates how to construct a JSON-formatted response using a Rust struct.

use loco_rs::{controller::{Json, format}, Result};

pub struct Health {
    pub ok: bool,
}

async fn ping() -> Result<Json<Health>> {
   format::json(Health { ok: true })
}

Structs§

RenderBuilder

Functions§

empty
Returns an empty response.
html
Returns an HTML response
json
Returns a JSON response containing the provided data.
render
text
Returns a response containing the provided text.
view
Render template located by key