/shopifyStoreAPI

Store API ready to run on Kubernetes

Primary LanguageGo

Code for Shopify Winter Internship challenge 2019.

shopifyStoreAPI is an application that provides basic RESTful online store functionality.

Installation with Docker

compose yourself

$ git clone https://github.com/kisulken/shopifyStoreAPI
$ cd shopifyStoreAPI
$ docker-compose build
$ docker-compose up

or run from the existing image

$ docker run -it kisulken/shopifystoreapi:v5

also, do not forget to populate your database

$ docker exec shopifystoredb psql -U postgres-dev dev < dump.sql

kubernetes mounting

$ kubectl create -f app-service.yaml,app-deployment.yaml,app-claim0-persistentvolumeclaim.yaml,db-deployment.yaml,db-service.yaml
$  kubectl port-forward $DB_POD_NAME 5432:5432
  ... in another window import dump.sql
$  psql -h localhost -p 5432 -U postgres-dev dev

API endpoints

endpoint methods
/store GET, POST
/store/:storeid GET, PATCH, DELETE
/store/:storeid/products GET, POST
/store/:storeid/products/:productid GET, PATCH, DELETE
/store/:storeid/products/:productid/items GET, POST
/store/:storeid/products/:productid/items/:itemid GET, DELETE
/store/:storeid/products/:productid/items/:itemid/order POST, DELETE
/store/:storeid/orders GET, POST
/store/:storeid/orders/:orderid GET, DELETE

API responses

All API endpoints will respond with a content-type application/json, corresponding http codes and contain a valid json data.

GET methods will respond with requested data i.e store information, product information etc. in case of success

[
    {
        "id": 1,
        "name": "My very cool store",
        "description": "Descriptive description"
    }
]

"not found" in case if the requested data was not located in the database

{
    "status": "fail",
    "data": "not found"
}

POST methods in case of successful insertion will respond with

{
    "status": "ok",
    "data": id
}

where id is a decimal number representing a unique identifier of the object

All other methods in case of success will respond with

{
    "status": "ok"
}

and in case of failure

{
    "status": "fail",
    "data": "error message"
}

API docs

1. Store

  • /store

GET - returns all available stores.

POST - create a new store.

{
  "name": "My cool store",
  "description": "Store description"
}
  • /store/:storeid

GET - get specified store with id.

PATCH - update a specific store's information.

DELETE - delete a specific store.

All the endpoints below follow the same pattern of GET, POST, PATCH, DELETE as the store endpoints described above.

2. Products

  • /store/:storeid/products

GET

POST

{
  "name": "Phone",
  "price": 999.9
}
  • /store/:storeid/products/:productid

GET, PATCH, DELETE

3. Items

  • /store/:storeid/products/:productid/items

GET

POST

json body is not required
  • /store/:storeid/products/:productid/items/:itemid

GET, DELETE

  • /store/:storeid/products/:productid/items/:itemid/order?id=yourOrderId

POST - Adds an item with :itemid to the existing order with a specified ID automatically adding a price of the product to the total

DELETE - Removes an item with :itemid from the existing order with a specified ID automatically deducting the cost of the item

4. Orders

  • /store/:storeid/orders

GET - returns all non-empty orders.

POST - creates a new empty order.

json body is not required
  • /store/:storeid/orders/:orderid

GET - get a specific order.

DELETE - delete a specific order (all the related items must be unattached/removed beforehand).


Author: Daniil Furmanov @ github.com/kisulken