You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
It seems Giraffe doesn't offer any other built-in solutions for this.
Have you explored potential solutions at https://giraffe.wiki/docs? The current content is lacking, and I believe we should add a new section there, even if it doesn't specifically pertain to Giraffe.
That's a good idea, it could be added similarly how Response Caching was mentioned. It's mostly deferring that responsibility to the already available ASP.NET Core Middleware and I'd highly encourage to continue doing that wherever possible. The original ethos of Giraffe was always to make ASP.NET Core more functional and great experience for F# as well, not so much to complete with it doing things differently. Unless there is really good reason why Giraffe should have its own static file handler I think the ASP.NET Core middleware is the preferable option.
Nothing prevents one though to expose a file themselves through a Giraffe handler. In HTTP there is no difference between a static file or a dynamic JSON response, both is just data returned in the HTTP body with slightly different headers. Someone can always stream the bytes from a file into the response and set the required HTTP headers (e.g. application/pdf or image/png, etc.) for the type of content that is being returned. It's just a plain handler like everything else.
Hi,
I see the following functions that emits
text/html
in Giraffe namespace but can't find one fortext/css
. How can I send css file through an endpoint?Thanks,
The text was updated successfully, but these errors were encountered: