emptygif
ภาษา: ไทย

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

Dart Frog Dart

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

Dart Frog Dart

ติดตั้ง
dart pub global activate dart_frog_cli
ไฟล์
pixel.gif.dart
รัน
dart_frog dev
// routes/pixel.gif.dart: the file name is the route.
import 'dart:convert';

import 'package:dart_frog/dart_frog.dart';

final _gif = base64Decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');

Response onRequest(RequestContext context) {
  return Response.bytes(
    body: _gif,
    headers: {'content-type': 'image/gif', 'cache-control': 'no-store'},
  );
}

เรารันตัวอย่างโค้ดนี้และเทียบไบต์ที่ได้กลับมาแล้ว

ตรวจสอบ

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

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

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