Escrever uma APIREST que a vovó possa guardar dados dos seus clientes
- linux
- goland ide
- go1.22.0
- package gorilla/mux
routes
API ROUTE |
DESCRIPTION |
STATUS |
[GET] /customers |
Retrieve all the customers |
200 |
[GET] /customer/{id} |
Retrieve a customer by ID |
200 |
[POST] /customers |
Add a new customer |
200 |
initial set of data
homepage
curl --location 'http://localhost:8010/'
200 OK
Bem vinde à página da Vovó
get all customers
curl --location 'http://localhost:8010/customers'
200 OK
[
{
"id": 1,
"firstName": "Ana",
"lastName": "Maria",
"email": "ana@email.com",
"address": {
"city": "São Paulo",
"state": "SP"
}
},
{
"id": 2,
"firstName": "Maria",
"lastName": "Clara",
"email": "maria@email.com",
"address": {
"city": "Belo Horizonte",
"state": "MG"
}
}
]
get all customer by ID
curl --location 'http://localhost:8010/customer/1'
200 OK
{
"id": 1,
"firstName": "Ana",
"lastName": "Maria",
"email": "ana@email.com",
"address": {
"city": "São Paulo",
"state": "SP"
}
}
add a customer
curl --location 'http://localhost:8010/customers' \
--header 'Content-Type: application/json' \
--data-raw '{
"firstName": "John",
"lastName": "Doe",
"email": "john@email.com",
"address": {
"city": "Salvador",
"state": "BA"
}
}'
200 OK
{
"id": 3,
"firstName": "Joao",
"lastName": "Doe",
"email": "joao@email.com",
"address": {
"city": "Salvador",
"state": "BA"
}
}