This repository contains code for the Customer shopcart for an e-commerce web site. This shows how to create a REST API with subordinate resources like shopcarts that have items:
Note: This repo has a both a .devcontainer folder and a Vagrantfile for two ways to bring up a development environment.
The best way to use this repo is to start your own repo using it as a git template. To do this just press the green Use this template button in GitHub and this will become the source for your repository.
You can also clone this repository and then copy and paste the starter code into your project repo folder on your local computer. Be careful not to copy over your own README.md
file so be selective in what you copy.
There are 4 hidden files that you will need to copy manually if you use the Mac Finder or Windows Explorer to copy files from this folder into your repo folder.
These should be copied using a bash shell as follows:
cp .gitignore ../<your_repo_folder>/
cp .flaskenv ../<your_repo_folder>/
cp .gitattributes ../<your_repo_folder>/
The project uses honcho which gets it's commands from the Procfile
. To start the service simply use:
$ honcho start
You should be able to reach the service at: http://localhost:8000. The port that is used is controlled by an environment variable defined in the .flaskenv
file which Flask uses to load it's configuration from the environment by default.
The project contains the following:
.gitignore - this will ignore vagrant and other metadata files
.flaskenv - Environment variables to configure Flask
.gitattributes - File to gix Windows CRLF issues
.devcontainers/ - Folder with support for VSCode Remote Containers
dot-env-example - copy to .env to use environment variables
requirements.txt - list if Python libraries required by your code
config.py - configuration parameters
service/ - service python package
├── __init__.py - package initializer
├── models.py - module with business models
├── routes.py - module with service routes
└── common - common code package
├── error_handlers.py - HTTP error handling code
├── log_handlers.py - logging setup code
└── status.py - HTTP status constants
tests/ - test cases package
├── __init__.py - package initializer
├── test_models.py - test suite for business models
└── test_routes.py - test suite for service routes
These are the RESTful routes for shopcarts
and items
Endpoint Methods Rule
---------------- ------- -----------------------------------------------------
index GET /
list_shopcarts GET /shopcarts
create_shopcarts POST /shopcarts
get_shopcarts GET /shopcarts/<shopcart_id>
update_shopcarts PUT /shopcarts/<shopcart_id>
delete_shopcarts DELETE /shopcarts/<shopcart_id>
list_items GET /shopcarts/<int:shopcart_id>/items
create_items POST /shopcarts/<shopcart_id>/items
get_items GET /shopcarts/<shopcart_id>/items/<item_id>
update_items PUT /shopcarts/<shopcart_id>/items/<item_id>
delete_items DELETE /shopcarts/<shopcart_id>/items/<item_id>
The test cases have 95% test coverage and can be run with nosetests
.
make login
to login to IBM Cloud, authenticate with the container registry, and pull down the cluster configurationmake build
to build Docker imageskubectl apply -n dev -f deploy/postgresql.yaml
kubectl create -n dev -f deploy/deployment.yaml
kubectl create -n dev -f deploy/service.yaml
make login
to login to IBM Cloud, authenticate with the container registry, and pull down the cluster configurationkubectl -n dev get all
to see everything running under dev
namespacekubectl -n dev get service
to see services running under dev
namespaceibmcloud ks workers --cluster nyu-devops --output json | jq -r '.[0].publicIP'
to see the public IPWORKERNODE_PUBLIC_IP:31001
, replace the WORKERNODE_PUBLIC_IP
with the public IP you got from the previous step