This repo contains two implementations of a simple CRUD API to manage a single entity: pets. The two implementations are identical in terms of the API interface, but differ in their internal architecture.
Example requests that can be executed against the API are provided in the requests.http file.
Both implementations expose the same interface:
simpleruns onhttp://localhost:8080enterpriseruns onhttp://localhost:8081
The examples below target the enterprise implementation on port 8081 — swap in 8080 to hit simple instead.
Create a pet:
curl -X POST http://localhost:8081/pets \
-H "Content-Type: application/json" \
-d '{
"name": "Rex 2",
"dob": "2020-05-17",
"type": "dog"
}'List all pets:
curl http://localhost:8081/petsGet a single pet:
curl http://localhost:8081/pets/1Update a pet:
curl -X PUT http://localhost:8081/pets/1 \
-H "Content-Type: application/json" \
-d '{
"name": "Rex the Great",
"dob": "2020-05-17",
"type": "dog"
}'Delete a pet:
curl -X DELETE http://localhost:8081/pets/1Get a missing pet (expect 404):
curl -i http://localhost:8081/pets/9999Invalid payload (expect 400):
curl -i -X POST http://localhost:8081/pets \
-H "Content-Type: application/json" \
-d '{
"name": "",
"dob": "not-a-date",
"type": ""
}'Create a pet:
Invoke-RestMethod -Method Post -Uri "http://localhost:8081/pets" `
-ContentType "application/json" `
-Body '{
"name": "Rex 2",
"dob": "2020-05-17",
"type": "dog"
}'List all pets:
Invoke-RestMethod -Uri "http://localhost:8081/pets"Get a single pet:
Invoke-RestMethod -Uri "http://localhost:8081/pets/1"Update a pet:
Invoke-RestMethod -Method Put -Uri "http://localhost:8081/pets/1" `
-ContentType "application/json" `
-Body '{
"name": "Rex the Great",
"dob": "2020-05-17",
"type": "dog"
}'Delete a pet:
Invoke-RestMethod -Method Delete -Uri "http://localhost:8081/pets/1"Get a missing pet (expect 404):
try {
Invoke-RestMethod -Uri "http://localhost:8081/pets/9999"
} catch {
$_.Exception.Response.StatusCode
}Invalid payload (expect 400):
try {
Invoke-RestMethod -Method Post -Uri "http://localhost:8081/pets" `
-ContentType "application/json" `
-Body '{
"name": "",
"dob": "not-a-date",
"type": ""
}'
} catch {
$_.Exception.Response.StatusCode
}