This project is hosted on Heroku. It can be accessed here https://shoppinglistapi1.herokuapp.com
The ShoppingList API is a simple REST API built with Python and the Flask web application framework.
It consists of the following features:-
- Register a new user
- Login a user
- Logout a logged in user
- Reset password for a registered user
- Add shoppinglists/items
- Edit shoppinglists/items
- Delete shoppinglists/items
| Type | API EndPoint | Public Access | Usage |
|---|---|---|---|
| POST | /api/v1/auth/register |
TRUE | Register a new user: requires an email and a password |
| POST | /api/v1/auth/login |
TRUE | Log in a registered user using their email and password |
| POST | /api/v1/auth/logout |
TRUE | Use a generated authentication token to logout a user |
| POST | /api/v1/auth/reset-password |
TRUE | Change the password for a registered user |
| POST | /api/v1/shoppinglists |
FALSE | Add a shopping list to a logged in user account |
| GET | /api/v1/shoppinglists |
FALSE | View all shopping lists associated with a user account |
| GET | /api/v1/shoppinglists/<id> |
FALSE | View the details of a shopping list specified by <id> |
| PUT | /api/v1/shoppinglists/<id> |
FALSE | Edit the attributes of a shopping list using its <id> |
| DELETE | /api/v1/shoppinglists/<id> |
FALSE | Deletes shopping list with <id> |
| POST | /api/v1/shoppinglists/<id>/items/ |
FALSE | Add item to the shopping list with that <id> |
| GET | /api/v1/shoppinglists/<id>/items/ |
FALSE | View all items in the shopping list with that <id> |
| GET | /api/v1/shoppinglists/<id>/items/<item_id> |
FALSE | View one item on a shoppinglist with its ID <id> and item ID <item_id> |
| PUT | /api/v1/shoppinglists/<id>/items/<item_id> |
FALSE | Edit a shopping list item specified by <item_id> |
| DELETE | /api/v1/shoppinglists/<id>/items/<item_id> |
FALSE | Delete an item from the specified shopping list |
It is assumed that you have Python 3.6 and Git installed on your local environment. Check to ensure that both are added to Path.
Start by cloning this repository. This will create a directory ShoppingListAPI
on your local machine.
$ git clone https://github.com/isheebo/ShoppingListAPIIn this directory/folder, You would need to create a Python virtual environment and activate it.
If the virtualenv package is not installed globally, run pip install virtualenv from the commandline. Then, a
virtual environment with name virtualenv can be created by running
$ virtualenv -p python3 ./virtualenvOn Windows, create the virtual environment as indicated below
$ virtualenv --python=<path to your python 3 executable> ./virtualenvwhere by the virtualenv is the virtual environment folder created in the
ShoppingListAPI directory.
Then you can activate the virtual environment and install the requirements as shown below:-
On Unix (MacOS X, Linux and BSD) based systems,
$ source virtualenv/bin/activate
$ pip3 install -r requirements.txtOn Windows,
$ cd virtualenv/scripts
$ activate
$ cd ..
$ cd ..
$ pip install -r requirements.txtNote:
- To install the requirements using
pipas mentioned above, make sure you are in the root folder (ShoppingListAPI folder). That is, where the filerequirements.txtis located in the directory tree. - on MacOSx, Linux & BSD,
pip3should be used instead ofpip.
-
PostgreSQL is utilised on the backend. If you are unfamiliar with the commandline, I would recommend you install your PostgresSQL from the PostgresSQL website. This option comes with the
pgAdminutility (or Postgres.app for MacOs X) which may be easier to interact with when compared to the terminal or the HomeBrew installation. -
If you have PostgresSQL installed, create databases
ShoppingListandShoppingListTest. (if you use other database names, change theSQLALCHEMY_DATABASE_URLinconfig.pyto reflect the URLs of your databases.) -
Create a file
settings.pyin the root of your project (at the same level asmanage.pyfile). -
In the
settings.pyfile, create DATABASE_URL and TEST_DATABASE_URL variables and assign the database URL and the test database URL respectively to the created variables. -
To check if you have properly configured your databases, run
$ python manage.py db init
$ python manage.py db migrate
$ python manage.py db upgrade
$ python3 manage.py runserver
This will start at server running at address http://127.0.0.1:5000 . Append any endpoints to the end of this URL (e.g. http://127.0.0.1:5000/api/v1/auth/register) so as to test them. I would recommend you use Postman for testing.
To run the tests of the project, use
$ nosetests -v --rednose --with-coverage --cover-package=app