API นี้ใช้สำหรับจัดการข้อมูล token ของผู้ใช้ โดยใช้ Express.js และ Redis เป็นฐานข้อมูล
-
ติดตั้ง dependencies:
npm install express ioredis zod -
ตั้งค่า Redis server ของคุณ
-
รันแอปพลิเคชัน:
node app.js
ดึงข้อมูล token ของผู้ใช้
สร้างหรืออัปเดตข้อมูล token ของผู้ใช้
ลบข้อมูล token ของผู้ใช้
ข้อมูล token ประกอบด้วย:
user_id: stringinput_token: numberoutput_token: number
-
ดึงข้อมูล token:
GET http://localhost:4250/token/user123 -
สร้าง/อัปเดตข้อมูล token:
POST http://localhost:4250/token Content-Type: application/json { "user_id": "user123", "input_token": 100, "output_token": 50 } -
ลบข้อมูล token:
DELETE http://localhost:4250/token/user123
- API นี้ใช้ Zod สำหรับตรวจสอบความถูกต้องของข้อมูล
- ข้อมูลถูกเก็บใน Redis โดยใช้ key ในรูปแบบ
user_{userId} - เซิร์ฟเวอร์ทำงานบนพอร์ต 4250