Table of Contents
- Django
- and ❤️
To get a local copy up and running follow these simple example steps.
-
Make sure your Docker daemon is running by starting up your Docker Desktop app
-
Run Docker Compose and build your Docker image by using this line in your terminal:
docker-compose up -d --build
Alternatively if the image is already built, you can run:
docker-compose up -d
-
Run migrations:
docker-compose exec web python manage.py migrate
- Server is now running on http://127.0.0.1:8000/
There are several endpoints that can be used:
- http://127.0.0.1:8000/ (the home page)
- http://127.0.0.1:8000/spend_points
- http://127.0.0.1:8000/get_balance
- http://127.0.0.1:8000/admin (if you create a superuser)
A neat thing about the Django Rest Framework is that if you go directly to directly to one of these URLs (while the server is running) you can see information about the endpoint such as what http request methods are allowed.
Endpoints that allow POST/PUT methods even have text areas for you to add JSON and submit without using a client like Postman or Insomnia.
http://127.0.0.1:8000/ (the home page)
- allows a GET request to retrieve a list of all transactions in the database and their initial point amounts
- allows a POST request to add single transactions:
{ "payer": "DANNON", "points": 1000, "timestamp": "2020-11-02T14:00:00Z" }
http://127.0.0.1:8000/spend_points
- allows a POST request to spend points:
{ "points": 5000 }
http://127.0.0.1:8000/get_balance
- allows a GET request to retrieve total rewards points available per payer
- if you are curious about one of my favorite Django features run this in your terminal:
and then follow the prompts that follow. This will add you as a super user to your django server which you will then use to sign in to the admin site. Here you can play around, see existing transactions, and create some new transactions.
docker-compose exec web python manage.py createsuperuser
- Setup new Django Project
- Add Black for code formatting
- Initial README work
- Setup project with PostgreSQL
- Setup endpoints
- Document the API
- Add tests if for a production environment
Joshua Dyer - [email protected]