emptygif
Bahasa: Bahasa Indonesia

Semua bahasa dan framework

Dream OCaml

Snippet OCaml untuk Dream yang menjawab request ke /pixel.gif dengan empty GIF, yang di-decode sekali saat startup.

Dream OCaml

Instal
opam install dream base64
File
pixel.ml
Jalankan
dune exec ./pixel.exe
(* dune: (executable (name pixel) (libraries dream base64)) *)
let gif = Base64.decode_exn "R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="

let () =
  Dream.run ~interface:"0.0.0.0" ~port:8080
  @@ Dream.logger
  @@ Dream.router
       [
         Dream.get "/pixel.gif" (fun _ ->
             Dream.respond
               ~headers:[ ("Content-Type", "image/gif"); ("Cache-Control", "no-store") ]
               gif);
       ]

Dicek terhadap dokumentasi terbaru framework tersebut.

Periksa

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

Situs resmi: Dream