Javalin Java
ตัวอย่างโค้ด Java สำหรับ Javalin ที่ตอบคำขอไปยัง /pixel.gif ด้วย GIF ว่าง ซึ่งถอดรหัสเพียงครั้งเดียวตอนเริ่มทำงาน
Javalin Java
import io.javalin.Javalin;
import java.util.Base64;
public class Pixel {
private static final byte[] GIF = Base64.getDecoder().decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
public static void main(String[] args) {
Javalin.create(config -> {
config.routes.get("/pixel.gif", ctx -> {
ctx.contentType("image/gif");
ctx.header("Cache-Control", "no-store");
ctx.result(GIF);
});
}).start(8080);
}
}
เรารันตัวอย่างโค้ดนี้และเทียบไบต์ที่ได้กลับมาแล้ว
ตรวจสอบ
curl -sI http://localhost:8080/pixel.gif