shared-framework 0.0.17

Reusable building blocks for HTTP services — Hyper routing, SeaORM data layer, validation, OpenAPI docs, jobs, queues, cache.
Documentation
//! HTML responses: shortcut for returning rendered markup from handlers.
//!
//! [`HtmlServiceResult::ok`] wraps an HTML string in a 200 [`ServiceResult`](super::ServiceResult)
//! with [`ResponseType::Html`](super::ResponseType), so the router renders it as `text/html`.
//! ```ignore
//! async fn page(ctx: CorrelationContext) -> Result<ServiceResult<String>, ErrorResult> {
//!     Ok(HtmlServiceResult::ok("<h1>Hello</h1>"))
//! }
//! ```

use super::{ResponseType, ServiceResult};

/// Shortcut constructors for HTML handler results.
pub struct HtmlServiceResult;

impl HtmlServiceResult {
    /// Wraps `html` in a 200 success result rendered as `text/html`.
    pub fn ok(html: impl Into<String>) -> ServiceResult<String> {
        ServiceResult::new("success", "OK", Some(html.into()), 200)
            .with_response_type(ResponseType::Html)
    }
}