Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HhW8LD8r3EigoBaCGrQZx5 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HhW8LD8r3EigoBaCGrQZx5
58 lines
2.9 KiB
Plaintext
58 lines
2.9 KiB
Plaintext
# Create, read, list, update, delete against MySQL. Each block is the curl command, then the status line, the Location header if any, and the body. The test uses a random port; it is printed as 8080.
|
|
|
|
|
|
--- create three books ---
|
|
$ curl -i -X POST 'localhost:8080/api/books' -H 'Content-Type: application/json' -d '{"title":"Effective Java","author":"Joshua Bloch","isbn":"9780134685991","price":45.50}'
|
|
HTTP 201 Location: http://localhost:8080/api/books/1
|
|
{"id":1,"title":"Effective Java","author":"Joshua Bloch","isbn":"9780134685991","price":45.50}
|
|
|
|
$ curl -i -X POST 'localhost:8080/api/books' -H 'Content-Type: application/json' -d '{"title":"Java Concurrency in Practice","author":"Brian Goetz","isbn":"9780321349606","price":39.99}'
|
|
HTTP 201 Location: http://localhost:8080/api/books/2
|
|
{"id":2,"title":"Java Concurrency in Practice","author":"Brian Goetz","isbn":"9780321349606","price":39.99}
|
|
|
|
$ curl -i -X POST 'localhost:8080/api/books' -H 'Content-Type: application/json' -d '{"title":"Clean Code","author":"Robert Martin","isbn":"9780132350884","price":33.00}'
|
|
HTTP 201 Location: http://localhost:8080/api/books/3
|
|
{"id":3,"title":"Clean Code","author":"Robert Martin","isbn":"9780132350884","price":33.00}
|
|
|
|
|
|
--- read one ---
|
|
$ curl -i -X GET 'localhost:8080/api/books/1'
|
|
HTTP 200
|
|
{"id":1,"title":"Effective Java","author":"Joshua Bloch","isbn":"9780134685991","price":45.50}
|
|
|
|
|
|
--- list, two per page ---
|
|
$ curl -i -X GET 'localhost:8080/api/books?page=0&size=2'
|
|
HTTP 200
|
|
{"content":[{"id":1,"title":"Effective Java","author":"Joshua Bloch","isbn":"9780134685991","price":45.50},{"id":2,"title":"Java Concurrency in Practice","author":"Brian Goetz","isbn":"9780321349606","price":39.99}],"page":0,"size":2,"totalElements":3,"totalPages":2}
|
|
|
|
$ curl -i -X GET 'localhost:8080/api/books?page=1&size=2'
|
|
HTTP 200
|
|
{"content":[{"id":3,"title":"Clean Code","author":"Robert Martin","isbn":"9780132350884","price":33.00}],"page":1,"size":2,"totalElements":3,"totalPages":2}
|
|
|
|
|
|
--- filter by author ---
|
|
$ curl -i -X GET 'localhost:8080/api/books?author=goetz'
|
|
HTTP 200
|
|
{"content":[{"id":2,"title":"Java Concurrency in Practice","author":"Brian Goetz","isbn":"9780321349606","price":39.99}],"page":0,"size":5,"totalElements":1,"totalPages":1}
|
|
|
|
|
|
--- update the price ---
|
|
$ curl -i -X PUT 'localhost:8080/api/books/1' -H 'Content-Type: application/json' -d '{"title":"Effective Java","author":"Joshua Bloch","isbn":"9780134685991","price":42.00}'
|
|
HTTP 200
|
|
{"id":1,"title":"Effective Java","author":"Joshua Bloch","isbn":"9780134685991","price":42.00}
|
|
|
|
|
|
--- delete, then ask for it again ---
|
|
$ curl -i -X DELETE 'localhost:8080/api/books/3'
|
|
HTTP 204
|
|
|
|
$ curl -i -X GET 'localhost:8080/api/books/3'
|
|
HTTP 404
|
|
{"detail":"Book 3 not found","instance":"/api/books/3","status":404,"title":"Not Found"}
|
|
|
|
|
|
--- what is in the table now (read with SQL, not through the API) ---
|
|
id=1 title=Effective Java price=42.00
|
|
id=2 title=Java Concurrency in Practice price=39.99
|