Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PETS API

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.

The API interface

Example requests that can be executed against the API are provided in the requests.http file.

Both implementations expose the same interface:

  • simple runs on http://localhost:8080
  • enterprise runs on http://localhost:8081

The examples below target the enterprise implementation on port 8081 — swap in 8080 to hit simple instead.

curl examples

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/pets

Get a single pet:

curl http://localhost:8081/pets/1

Update 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/1

Get a missing pet (expect 404):

curl -i http://localhost:8081/pets/9999

Invalid payload (expect 400):

curl -i -X POST http://localhost:8081/pets \
  -H "Content-Type: application/json" \
  -d '{
    "name": "",
    "dob": "not-a-date",
    "type": ""
  }'

PowerShell examples

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
}

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages