Files
java-interview-lab/library-management/scripts/api-demo.sh
T
Claude 26ece9cc9b Add library-management module: console app evolved into a Spring Boot 4 REST API
Stage 2 console classes and the shared LoanPolicy, then a Spring Boot 4.1.2 + JPA API
(H2, @Version optimistic locking, problem+json errors). Tests write output/ transcripts
while asserting the same numbers; scripts regenerate everything.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b4DPL6dtpFg4U4LHc2
2026-11-14 21:21:16 +05:30

24 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Drives a running API (scripts/run.sh --detach) with curl: the same story as the console demo,
# against a real servlet container. Dates in the output are "today", so they differ per run.
set -uo pipefail
BASE=${BASE:-http://localhost:8080/api}
call() { # method path [json]
echo "> $1 $2${3:+ $3}"
if [ -n "${3:-}" ]; then
curl -s -X "$1" "$BASE$2" -H 'Content-Type: application/json' -d "$3" -w '\n< HTTP %{http_code}\n\n'
else
curl -s -X "$1" "$BASE$2" -w '\n< HTTP %{http_code}\n\n'
fi
}
call POST /books '{"isbn":"978-0134685991","title":"Effective Java","author":"Joshua Bloch","copies":2}'
call POST /books '{"isbn":"978-0596009205","title":"Head First Java","author":"Kathy Sierra","copies":1}'
call POST /books '{"isbn":"","title":"","author":"Nobody","copies":0}'
call POST /members '{"name":"Asha","email":"[email protected]"}'
call POST /members '{"name":"Ravi","email":"not-an-email"}'
call POST /members '{"name":"Ravi","email":"[email protected]"}'
call POST /loans '{"memberId":1,"bookId":2}'
call POST /loans '{"memberId":2,"bookId":2}'
call POST /loans/1/return
call GET /books