emptygif
ภาษา: ไทย

ภาษาและเฟรมเวิร์กทั้งหมด

Kemal Crystal

ตัวอย่างโค้ด Crystal สำหรับ Kemal ที่ตอบคำขอไปยัง /pixel.gif ด้วย GIF ว่าง ซึ่งถอดรหัสเพียงครั้งเดียวตอนเริ่มทำงาน

Kemal Crystal

ติดตั้ง
shards install # shard.yml: dependencies: kemal: github: kemalcr/kemal
ไฟล์
src/server.cr
รัน
crystal run src/server.cr
require "base64"
require "kemal"

GIF = Base64.decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")

get "/pixel.gif" do |env|
  env.response.content_type = "image/gif"
  env.response.headers["Cache-Control"] = "no-store"
  env.response.write(GIF) # write the bytes; a non-String return value is ignored
  nil
end

Kemal.run(8080)

ตรวจสอบกับเอกสารปัจจุบันของเฟรมเวิร์กแล้ว

ตรวจสอบ

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

เว็บไซต์ทางการ: Kemal

เพิ่มเติมใน Crystal