From 41c4bc25e6f685d10d3b82d851c152c126fde25b Mon Sep 17 00:00:00 2001 From: Dotan Nahum Date: Thu, 7 Dec 2023 08:40:32 +0200 Subject: [PATCH] feat: format::html --- CHANGELOG.md | 6 ++++++ src/controller/format.rs | 26 +++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..1d601fdf6 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,6 @@ +# Changelog + +## vNext + +* Added: `format:html` [https://github.com/loco-rs/loco/issues/74](https://github.com/loco-rs/loco/issues/74) + diff --git a/src/controller/format.rs b/src/controller/format.rs index cac338ced..e9d7fe42d 100644 --- a/src/controller/format.rs +++ b/src/controller/format.rs @@ -20,7 +20,7 @@ //! } //! ``` -use axum::Json; +use axum::{response::Html, Json}; use crate::Result; @@ -96,3 +96,27 @@ pub fn text(t: &str) -> Result { pub fn json(t: T) -> Result> { Ok(Json(t)) } + +/// Returns an HTML response +/// +/// # Example: +/// +/// ```rust +/// use loco_rs::{ +/// controller::format, +/// Result, +/// }; +/// use axum::Html; +/// +/// async fn endpoint() -> Result> { +/// format::html("hello, world") +/// } +/// ``` +/// +/// # Errors +/// +/// Currently this function did't return any error. this is for feature +/// functionality +pub fn html(content: &str) -> Result> { + Ok(Html(content.to_string())) +}