Final project for Udacity Go Nanodegree
First install Chi
go get -u github.com/go-chi/chi/v5
Run
go run
Now the API is ready on your localhost
- Endpoint
GET localhost:3000/customers/1
- Sample response
{
"id": 1,
"name": "Logan Roy",
"role": "CEO",
"email": "[email protected]",
"phone": "212-111-1111"
}
- Endpoint
GET localhost:3000/customers/1
- Sample response
{
"1": {
"id": 1,
"name": "Logan Roy",
"role": "CEO",
"email": "[email protected]",
"phone": "212-111-1111"
},
"2": {
"id": 2,
"name": "Tom Wambsgans",
"role": "Head of Media",
"email": "[email protected]",
"phone": "212-222-2222",
"contacted": true
},
"3": {
"id": 3,
"name": "Nan Pierce",
"role": "CEO",
"email": "[email protected]",
"phone": "212-333-3333"
}
}
- Endpoint
POST localhost:3000/customers
- Request body
{
"id": 4,
"name": "Sioban Roy",
"role": "Nepo Baby",
"email": "[email protected]",
"phone": "212-444-4444"
}
- Sample response
{
"id": 4,
"name": "Sioban Roy",
"role": "Nepo Baby",
"email": "[email protected]",
"phone": "212-444-4444"
}
- Endpoint
PUT localhost:3000/customers/1
- Request body
{
"id": 1,
"name": "Logan Roy",
"role": "Former CEO",
"email": "[email protected]",
"phone": "212-111-1111"
}
- Sample response
{
"id": 1,
"name": "Logan Roy",
"role": "Former CEO",
"email": "[email protected]",
"phone": "212-111-1111"
}
- Endpoint
DELETE localhost:3000/customers/1
- Sample response
{
"id": 1,
"name": "Logan Roy",
"role": "Former CEO",
"email": "[email protected]",
"phone": "212-111-1111"
}