Giraffe
Giraffe copied to clipboard
how return css file via endpoint?
Hi,
I see the following functions that emits text/html
in Giraffe namespace but can't find one for text/css
. How can I send css file through an endpoint?
Thanks,
/// <summary>
/// Writes a HTML string to the body of the HTTP response.
/// It also sets the HTTP header Content-Type to text/html and sets the Content-Length header accordingly.
/// </summary>
/// <param name="html">The HTML string to be send back to the client.</param>
/// <returns>A Giraffe <see cref="HttpHandler" /> function which can be composed into a bigger web application.</returns>
let htmlString (html : string) : HttpHandler =
let bytes = Encoding.UTF8.GetBytes html
fun (_ : HttpFunc) (ctx : HttpContext) ->
ctx.SetContentType "text/html; charset=utf-8"
ctx.WriteBytesAsync bytes
/// <summary>
/// <para>Compiles a `Giraffe.GiraffeViewEngine.XmlNode` object to a HTML view and writes the output to the body of the HTTP response.</para>
/// <para>It also sets the HTTP header `Content-Type` to `text/html` and sets the `Content-Length` header accordingly.</para>
/// </summary>
/// <param name="htmlView">An `XmlNode` object to be send back to the client and which represents a valid HTML view.</param>
/// <returns>A Giraffe `HttpHandler` function which can be composed into a bigger web application.</returns>
let htmlView (htmlView : XmlNode) : HttpHandler =
let bytes = RenderView.AsBytes.htmlDocument htmlView
fun (_ : HttpFunc) (ctx : HttpContext) ->
ctx.SetContentType "text/html; charset=utf-8"
ctx.WriteBytesAsync bytes