#!/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":"asha@example.com"}' call POST /members '{"name":"Ravi","email":"not-an-email"}' call POST /members '{"name":"Ravi","email":"ravi@example.com"}' call POST /loans '{"memberId":1,"bookId":2}' call POST /loans '{"memberId":2,"bookId":2}' call POST /loans/1/return call GET /books