This project is a simple REST API built using Django and PostgreSQL that allows users to manage customer data and orders. It includes authentication via OpenID Connect and provides SMS notifications for new orders using the Africa's Talking SMS gateway.
- RESTful API for managing customers and orders
- User authentication and authorization using OpenID Connect
- SMS notifications for new orders
- Automated testing and Continuous Integration/Continuous Deployment (CI/CD) pipeline
- Deployed on Heroku
- Technologies Used
- Getting Started
- Project Structure
- API Endpoints
- Authentication
- Testing
- Deployment
- Contributing
- References
- Django: A high-level Python web framework that encourages rapid development and clean, pragmatic design. Learn more
- Django REST Framework: A powerful toolkit for building Web APIs in Django. Learn more
- PostgreSQL: An open-source relational database system. Learn more
- Gunicorn: A Python WSGI HTTP Server for UNIX. Learn more
- Whitenoise: A Django middleware for serving static files. Learn more
- Heroku: A cloud platform as a service (PaaS) supporting several programming languages. Learn more
To run this project locally, you will need:
- Python 3.9 or higher
- PostgreSQL installed locally
- pip (Python package installer)
git clone https://github.com/yourusername/your-repo-name.git
cd your-repo-name
python -m venv env
source env/bin/activate # On Windows use `env\Scripts\activate`
pip install -r requirements.txt
-
Open the PostgreSQL command line interface:
sudo -u postgres psql
-
Create a database and user:
CREATE DATABASE mydatabase; CREATE USER myuser WITH PASSWORD 'mypassword'; GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;
-
Update your Django settings in
settings.py
to connect to PostgreSQL:DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'mydatabase', 'USER': 'myuser', 'PASSWORD': 'mypassword', 'HOST': 'localhost', 'PORT': '5432', } }
python manage.py migrate
python manage.py runserver
The application should now be running at http://127.0.0.1:8000/
.
your-repo-name/
│
├── your_project_name/
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ ├── wsgi.py
│ └── asgi.py
│
├── your_app_name/
│ ├── migrations/
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── models.py
│ ├── serializers.py
│ ├── urls.py
│ └── views.py
│
├── requirements.txt
├── Procfile
└── README.md
-
Create a Customer
- POST
/api/customers/
- POST
-
Retrieve a Customer
- GET
/api/customers/{id}/
- GET
-
Update a Customer
- PUT
/api/customers/{id}/
- PUT
-
Delete a Customer
- DELETE
/api/customers/{id}/
- DELETE
-
Create an Order
- POST
/api/orders/
- POST
-
Retrieve an Order
- GET
/api/orders/{id}/
- GET
-
Update an Order
- PUT
/api/orders/{id}/
- PUT
-
Delete an Order
- DELETE
/api/orders/{id}/
- DELETE
The API uses OpenID Connect for authentication. When making requests to protected endpoints, include the authentication token in the Authorization
header:
Authorization: Bearer your_access_token
To obtain a token, you need to authenticate through your OpenID provider and retrieve the token.
To run the tests for the API, use the following command:
python manage.py test
The tests will provide coverage information and report any failing tests.
This application is deployed on Heroku. To deploy to Heroku, follow these steps:
-
Create a new Heroku app:
heroku create your-app-name
-
Push your code to Heroku:
git push heroku Dev-1:main
-
Run migrations on Heroku:
heroku run python manage.py migrate
-
Open the application:
heroku open
Contributions are welcome! If you have suggestions or improvements, feel free to create a pull request.
- Fork the repository.
- Create a new branch for your feature:
git checkout -b feature/YourFeature
- Commit your changes:
git commit -m 'Add a new feature'
- Push the branch:
git push origin feature/YourFeature
- Create a pull request.