Section 6: Lab: เอกสาร OpenAPI และ Minimal API
- สร้างเอกสาร OpenAPI ในตัวด้วย AddOpenApi และ MapOpenApi
- อธิบาย Endpoint ด้วย XML Comment และเปิดทดลองผ่าน Swagger UI หรือ Scalar
- Minimal API เทียบกับ Controller และควรเลือกใช้เมื่อใด
- MapGroup, TypedResults และ Validation ในตัวของ Minimal API ที่มาใน .NET 10
- Lab: เขียน API หมวดหมู่สินค้าใหม่ด้วย Minimal API พร้อมเอกสาร
Section 7: Lab: ป้องกัน API ด้วย Authentication และ Authorization
- Authentication กับ Authorization ต่างกันอย่างไร
- JWT Bearer Authentication และการตรวจสอบ Token
- ASP.NET Core Identity กับ Identity API Endpoints สำหรับออก Token
- Role, Claim และ Authorization Policy
- ตั้งค่า CORS ให้เว็บจากโดเมนอื่นเรียกใช้ได้อย่างปลอดภัย
Section 8: Versioning, Rate Limiting และ Caching
- API Versioning ด้วยแพ็กเกจ Asp.Versioning
- Rate Limiting Middleware เพื่อป้องกันการเรียกถี่เกินไป
- Output Caching และ HybridCache สำหรับข้อมูลที่อ่านบ่อย
- Health Check และ Logging ด้วย ILogger
- Checklist ความปลอดภัยก่อนเปิด API สู่ภายนอก
Section 9: Lab: ทดสอบและเรียกใช้ API
- Unit Test ชั้น Service ด้วย xUnit
- Integration Test ด้วย WebApplicationFactory และฐานข้อมูลทดสอบ
- เรียก API จากแอป .NET ด้วย IHttpClientFactory และ Typed Client
- จัดการ Timeout และ Retry เมื่อเรียกบริการภายนอก
Section 10: Workshop: สร้างและ Deploy API ครบวงจร
- โจทย์: API ระบบจองห้องประชุมหรือระบบงานที่ผู้เรียนเลือก
- ออกแบบ Resource, DTO, Validation และสิทธิ์การเข้าถึง
- ใช้ AI Assistant ช่วยเขียนโค้ดและตรวจทานผลก่อนใช้จริง
- สร้าง Container Image ด้วย dotnet publish และรันคู่กับ SQL Server ด้วย Docker Compose
- นำเสนอผลงานและสรุปแนวทางต่อยอด