LMS-BGN/docs/qa/assessments/curl-examples.md

69 lines
2.7 KiB
Markdown

# Contoh cURL untuk Backend LMS-BGN
> Pastikan server berjalan di `http://localhost:8000`.
## Health
curl -s http://localhost:8000/health | jq
## Courses
# List
curl -s "http://localhost:8000/api/courses?page=1&pageSize=20" | jq
# Detail
curl -s http://localhost:8000/api/courses/c1 | jq
# Detail 404
curl -s -o /dev/null -w "%{http_code}\n" http://localhost:8000/api/courses/unknown
## Modules - update progress
curl -s -X POST http://localhost:8000/api/modules/m1/progress \
-H "Content-Type: application/json" \
-d '{"progressPercent":50}' | jq
## Assignments - submission
# Missing idempotencyKey (expected 400)
curl -s -X POST http://localhost:8000/api/assignments/a1/submission \
-H "Content-Type: application/json" \
-d '{"content":"Answer"}' -o /dev/null -w "%{http_code}\n"
# Created (201)
curl -s -X POST http://localhost:8000/api/assignments/a1/submission \
-H "Content-Type: application/json" \
-d '{"content":"Answer","idempotencyKey":"abc"}' | jq
# Duplicate idempotency (409)
curl -s -X POST http://localhost:8000/api/assignments/a1/submission \
-H "Content-Type: application/json" \
-d '{"content":"Answer","idempotencyKey":"dup-key"}' -o /dev/null -w "%{http_code}\n"
## Exam Session
# Create requires fields (400)
curl -s -X POST http://localhost:8000/api/exam-session \
-H "Content-Type: application/json" \
-d '{}' -o /dev/null -w "%{http_code}\n"
# Create (201)
curl -s -X POST http://localhost:8000/api/exam-session \
-H "Content-Type: application/json" \
-d '{"examId":"exam-001","userId":"u1"}' | jq
# Score answers (replace SESSION_ID)
curl -s -X POST http://localhost:8000/api/exam-session/SESSION_ID/score \
-H "Content-Type: application/json" \
-d '{"idempotencyKey":"score-1","mode":"batch","answers":[{"questionId":"q1","choiceIndex":0},{"questionId":"q2","choiceIndex":2}]}' | jq
# Duplicate idempotency (409)
curl -s -X POST http://localhost:8000/api/exam-session/SESSION_ID/score \
-H "Content-Type: application/json" \
-d '{"idempotencyKey":"score-1","answers":[]}' -o /dev/null -w "%{http_code}\n"
# Summary
curl -s http://localhost:8000/api/exam-session/SESSION_ID/summary | jq
## Exams
# List
curl -s "http://localhost:8000/api/exams?page=1&pageSize=20" | jq
# Filter by q
curl -s "http://localhost:8000/api/exams?page=1&pageSize=20&q=HACCP" | jq
## Certificates
# Resend requires fields (400)
curl -s -X POST http://localhost:8000/api/certificates/abc/resend \
-H "Content-Type: application/json" \
-d '{"idempotencyKey":"id1"}' -o /dev/null -w "%{http_code}\n"
# Resend accepted and throttled
curl -s -X POST http://localhost:8000/api/certificates/abc/resend \
-H "Content-Type: application/json" \
-d '{"recipientEmail":"x@y.com","idempotencyKey":"cert-1"}' -o /dev/null -w "%{http_code}\n"