Giter VIP home page Giter VIP logo

cake-store-api's Introduction

cake-store-api

A RestFul API build using Go to demonstrate basic CRUD. Code organized using Clean Architecture.

How to run

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

API Documentation

Run in Postman

Or click this URL https://elements.getpostman.com/redirect?entityId=6929584-5922eef1-a2f0-44af-bab8-ca43e188999d&entityType=collection

The API has 5 endpoints:

  1. Create a Cake
  2. Get List of Cakes
  3. Get a Cake
  4. Update a Cake
  5. Delete a Cake

The API will return response with the following format:

{
  "code": number,
  "data": any,
  "error": string
}

Create a Cake

Request

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"
}'

Response

{
  "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 List Cakes

Request

GET /cakes

curl -X GET \
  'localhost:8000/cakes' \
  --header 'Accept: */*' \
  --header 'User-Agent: Thunder Client (https://www.thunderclient.com)'

Response

{
  "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 a Cake

Request

GET /cakes/:id

curl -X GET \
  'localhost:8000/cakes/1' \
  --header 'Accept: */*' \
  --header 'User-Agent: Thunder Client (https://www.thunderclient.com)'

Success Response

{
  "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"
  }
}

Error Response

{
  "code": 404,
  "error": "cake not found"
}

Update a Cake

Request

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"
}'

Success Response

{
  "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": ""
  }
}

Error Response

{
  "code": 404,
  "error": "cake not found"
}

Delete a Cake

Request

DELETE /cakes/:id


curl -X DELETE \
 'localhost:8000/cakes/5' \
 --header 'Accept: _/_' \
 --header 'User-Agent: Thunder Client (https://www.thunderclient.com)'

Success Response

Status Code: 204 No Content


Error Response

{
  "code": 404,
  "error": "cake not found"
}

cake-store-api's People

Contributors

guntoroyk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.