emptygif
भाषा: हिन्दी

सभी भाषाएँ और फ़्रेमवर्क

Ring + reitit Clojure

Ring + reitit के लिए Clojure स्निपेट, जो /pixel.gif पर आने वाली रिक्वेस्ट का जवाब empty GIF से देता है। GIF स्टार्टअप पर एक ही बार डिकोड होता है।

Ring + reitit Clojure

इंस्टॉल
{:deps {metosin/reitit-ring {:mvn/version "0.11.0"} ring/ring-jetty-adapter {:mvn/version "1.15.5"}}}
फ़ाइल
core.clj
चलाएँ
clojure -M -m pixel.core
(ns pixel.core
  (:require [reitit.ring :as ring]
            [ring.adapter.jetty :as jetty])
  (:import (java.util Base64)))

(def gif (.decode (Base64/getDecoder) "R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="))

(def app
  (ring/ring-handler
   (ring/router
    ["/pixel.gif" {:get (fn [_]
                        {:status 200
                         :headers {"Content-Type" "image/gif"
                                   "Content-Length" (str (alength gif))
                                   "Cache-Control" "no-store"}
                         :body gif})}])
   (ring/create-default-handler)))

(defn -main []
  (jetty/run-jetty app {:port 8080 :join? true}))

हमने यह स्निपेट चलाया और इसके लौटाए बाइट्स की तुलना की।

जाँचें

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

आधिकारिक साइट: Ring + reitit