A RestFul API build using Go to demonstrate basic CRUD. Code organized using Clean Architecture.
Clone the repository
git clone [email protected]:guntoroyk/cake-store-api.git
Run on docker
docker-compose up --build -d
The API will available at http://localhost:8000/cakes
Or click this URL https://elements.getpostman.com/redirect?entityId=6929584-5922eef1-a2f0-44af-bab8-ca43e188999d&entityType=collection
The API has 5 endpoints:
The API will return response with the following format:
{
"code": number,
"data": any,
"error": string
}
POST /cakes
curl -X POST \
'localhost:8000/cakes' \
--header 'Accept: */*' \
--header 'User-Agent: Thunder Client (https://www.thunderclient.com)' \
--header 'Content-Type: application/json' \
--data-raw '{
"title": "Lemon cheesecake 3",
"description": "A cheesecake made of lemon",
"rating": 7,
"image": "https://img.taste.com.au/ynYrqkOs/w720-h480-cfill-q80/taste/2016/11/sunny-lemon-cheesecake-102220-1.jpeg"
}'
{
"code": 201,
"data": {
"id": 5,
"title": "Lemon cheesecake 3",
"description": "A cheesecake made of lemon",
"rating": 7,
"image": "https://img.taste.com.au/ynYrqkOs/w720-h480-cfill-q80/taste/2016/11/sunny-lemon-cheesecake-102220-1.jpeg",
"created_at": "2022-12-06 09:26:50",
"updated_at": "2022-12-06 09:26:50"
}
}
GET /cakes
curl -X GET \
'localhost:8000/cakes' \
--header 'Accept: */*' \
--header 'User-Agent: Thunder Client (https://www.thunderclient.com)'
{
"code": 200,
"data": [
{
"id": 1,
"title": "Lemon cheesecake 1",
"description": "A cheesecake made of lemon",
"rating": 7,
"image": "https://img.taste.com.au/ynYrqkOs/w720-h480-cfill-q80/taste/2016/11/sunny-lemon-cheesecake-102220-1.jpeg",
"created_at": "2022-12-05 16:23:43",
"updated_at": "2022-12-05 16:59:13"
},
{
"id": 2,
"title": "Lemon cheesecake",
"description": "A cheesecake made of lemon",
"rating": 7,
"image": "https://img.taste.com.au/ynYrqkOs/w720-h480-cfill-q80/taste/2016/11/sunny-lemon-cheesecake-102220-1.jpeg",
"created_at": "2022-12-05 16:44:52",
"updated_at": "2022-12-05 16:44:52"
},
{
"id": 5,
"title": "Lemon cheesecake 3",
"description": "A cheesecake made of lemon",
"rating": 7,
"image": "https://img.taste.com.au/ynYrqkOs/w720-h480-cfill-q80/taste/2016/11/sunny-lemon-cheesecake-102220-1.jpeg",
"created_at": "2022-12-06 09:26:50",
"updated_at": "2022-12-06 09:26:50"
}
]
}
GET /cakes/:id
curl -X GET \
'localhost:8000/cakes/1' \
--header 'Accept: */*' \
--header 'User-Agent: Thunder Client (https://www.thunderclient.com)'
{
"code": 200,
"data": {
"id": 1,
"title": "Lemon cheesecake 1",
"description": "A cheesecake made of lemon",
"rating": 7,
"image": "https://img.taste.com.au/ynYrqkOs/w720-h480-cfill-q80/taste/2016/11/sunny-lemon-cheesecake-102220-1.jpeg",
"created_at": "2022-12-05 16:23:43",
"updated_at": "2022-12-05 16:59:13"
}
}
{
"code": 404,
"error": "cake not found"
}
PATC /cakes/:id
curl -X PATCH \
'localhost:8000/cakes/1' \
--header 'Accept: */*' \
--header 'User-Agent: Thunder Client (https://www.thunderclient.com)' \
--header 'Content-Type: application/json' \
--data-raw '{
"title": "Lemon cheesecake updated",
"description": "A cheesecake made of lemon updated",
"rating": 7,
"image": "https://img.taste.com.au/ynYrqkOs/w720-h480-cfill-q80/taste/2016/11/sunny-lemon-cheesecake-102220-1.jpeg"
}'
{
"code": 200,
"data": {
"id": 1,
"title": "Lemon cheesecake updated",
"description": "A cheesecake made of lemon updated",
"rating": 7,
"image": "https://img.taste.com.au/ynYrqkOs/w720-h480-cfill-q80/taste/2016/11/sunny-lemon-cheesecake-102220-1.jpeg",
"created_at": "",
"updated_at": ""
}
}
{
"code": 404,
"error": "cake not found"
}
DELETE /cakes/:id
curl -X DELETE \
'localhost:8000/cakes/5' \
--header 'Accept: _/_' \
--header 'User-Agent: Thunder Client (https://www.thunderclient.com)'
Status Code: 204 No Content
{
"code": 404,
"error": "cake not found"
}