This repository contains an API for the mobile application: HEADLINE. HEADLINE is an iOS (should be coming to Android anytime soon) that helps you get relevant news and happenings from top nigerian websites.
This application was developed using Flask. Postgres was used for persisting data with SQLAlchemy as ORM.
Development with docker has been made simple. To get started make sure you have docker on your PC. You can download it here. Follow the following steps carefully to set the project up:
- Create a
.envusing the.env.samplefile. - Run the command
docker-compose upto let the docker daemon start building the image and create the container. - When you're done, use the command
docker-compose downorCtrl + Cto stop the container.
Users are authenticated and validated using an werkzeug token. Generating tokens on login ensures each account is unique to a user and can't be accessed by an authenticated user.
- Start up your terminal (or Command Prompt on Windows OS).
- Ensure that you've
pythoninstalled on your PC. - Clone the repository by entering the command
git clone https://github.com/BolajiOlajide/HeadLineAPIin the terminal. - Navigate to the project folder using
cd HeadLineAPIon your terminal (or command prompt) - After cloning, create a virtual environment then install the requirements with the command:
pip install -r requirements.txt. - Create a
.envfile in your root directory as described in.env.samplefile. Variables such as DATABASE_URL and config are defined in the .env file and it is essential you create this file before running the application.
FLASK_CONFIG='default'
DATABASE_URI='database connection to be used'
SECRET_KEY='random string used for generating token'
TEST_DB='database to be used for testing'
SERVER_NAME='server in which app is being tested: `localhost:5000` works.'
- Docker Variables
DB_USER=postgres
DB_PASS=postgres
DB_SERVICE=postgres
DB_PORT=5432
DB_NAME=postgres
- After this, you'll need to migrate data schema to the database using the command:
python manage.py create_db.
- A customized interactive python shell can be accessed by passing the command
python manage.py shellon your terminal. - Once this is done, the application can be started using
python manage.py runserverand by default the application can be accessed athttp://127.0.0.1:5000orgunicorn manage:appwhich starts the application using port8000. The application starts using the configuration settings defined in your .env file.
The API currently has 4 different configuration which can be defined in the .env file.
production: this configuration starts the app ready for production to be deployed on any cloud application platform such as Heroku, AWS etc.development: this configuration starts the application in the development mode.testing: this configuration starts the application in a testing mode.default: this is the same as the development configuration.
The API has routes, each dedicated to a single task that uses HTTP response codes to indicate API status and errors.
The following features make up the BucketList API:
-
It uses itsdangerous-Serializer & werkzeug token for authentication.
-
It generates a token on successful login and returns it to the user.
-
It verifies the token to ensures a user is authenticated to access protected endpoints.
-
It allows users to be created.
-
It allows users to login and obtain a token
-
It allows authenticated users to retrieve and update their information.
URL Prefix = http://sample_domain/ where sample domain is the root URL of the server HOST.
| EndPoint | Functionality | Public Access |
|---|---|---|
| POST /auth/register | Register a user | TRUE |
| POST /auth/login | Logs a user in | TRUE |
POST /auth/loginINPUT:
{
"username":"username",
"password":"password"
}- HTTP Status:
200: OKJSON data
{
"token": "edasdnmdsakmkEcR4Ardmfsdamfkjdsjlasnfh)__QWEh"
}POST /auth/registerINPUT:
{
"username":"username",
"password":"password"
}- HTTP Status:
201: createdJSON data
{
"username": "test_user"
}