emptygif
Language: English

All languages and frameworks

Giraffe F#

A F# snippet for Giraffe that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

Giraffe F#

Install
dotnet add package Giraffe
File
Program.fs
Run
dotnet run
open System
open Microsoft.AspNetCore.Builder
open Microsoft.Extensions.DependencyInjection
open Giraffe

let gif = Convert.FromBase64String "R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="

let pixel: HttpHandler =
    setHttpHeader "Content-Type" "image/gif"
    >=> setHttpHeader "Cache-Control" "no-store"
    >=> setBody gif

let webApp =
    choose [
        GET >=> route "/pixel.gif" >=> pixel
        RequestErrors.NOT_FOUND "Not Found"
    ]

let builder = WebApplication.CreateBuilder()
builder.Services.AddGiraffe() |> ignore

let app = builder.Build()
app.UseGiraffe webApp
app.Run "http://0.0.0.0:8080"

We ran this snippet and compared the bytes it returned.

Check it

curl -sI http://localhost:8080/pixel.gif

Official site: Giraffe

More in F#