Restful API for a shoe store. It contains a implementation of Shoes with the following operations:
- Get all shoes.
- Get a shoe.
- Create a shoe.
- Update a shoe.
- Delete a shoe.
- Go.
- Gin Web Framework.
- GORM.
- PostgreSQL.
- Once you are in the
/main
folder run the command:
go run main.go
- Or run directly the command:
go run main/main.go
- Gin Web Framework:
go get -u github.com/gin-gonic/gin
- GORM (ORM library):
go get -u gorm.io/gorm
- Go Postgres driver:
go get github.com/lib/pq
export GO111MODULE=on
go mod tidy
Attribute | Type |
---|---|
id | int |
name | string |
color | string |
price | float64 |
GET
localhost:8080/api/v1/shoes
: indexes shoes.- Response example:
200 OK
[
{
"id": "1",
"name": "Nike SB",
"color": "Black",
"price": "150"
},
{
"id": "2",
"name": "Adidas Pictoris",
"color": "White",
"price": "200"
}
]
GET
localhost:8080/api/v1/shoes/{id}
: shows a shoe by the ID.- Response example:
200 OK
{
"id": "1",
"name": "Nike SB",
"color": "Black",
"price": "150"
}
POST
localhost:8080/api/v1/shoes
: stores a shoe getting it's attributes throught the JSON body.- Body example:
{
"name": "Nike SB",
"color": "Black",
"price": "150.00"
}
- Response example:
201 Created
{
"id": "1",
"name": "Nike SB",
"color": "Black",
"price": "150"
}
PUT
localhost:8080/api/v1/shoes/{id}
: updates a shoe by the ID getting it's attributes throught the JSON body.- Body example:
{
"name": "Nike SB",
"color": "White",
"price": "180.00"
}
- Response example:
200 OK
{
"id": "1",
"name": "Nike SB",
"color": "White",
"price": "180"
}
DELETE
localhost:8080/api/v1/shoes/{id}
: deletes a shoe by the ID.- Response example:
204 No Content