Skip to content

ahmetelgun/flask-boilerplate

Repository files navigation

Flask API Boilerplate

Simple Flask boilerplate with register, login, logout endpoints.

Installation

Clone the repository

git clone https://github.com/ahmetelgun/flask-boilerplate.git
cd flask-boilerplate

Activate virtualenv and install requirements

pipenv shell
pip install -r requirements.txt

Run tests

python -m unittest

Create Database

python models.py

Start the application

python app.py

Usage

flask-boilerplate has 4 enpoints.

/register [POST]

Body

{
    "firstname": "Anakin",
    "lastname": "Skywalker",
    "email": "anakin@skywalker.space",
    "password": "padme_amidala"
}

Response

Response takes 3 different response codes.

If user successfully created, returns 200.

If request is invalid, returns 400.

If email is already exists, returns 409.

Response with 200 status code

{
    "message": "User successfuly created"
}

/login [POST]

Body

{
    "email": "anakin@skywalker.space",
    "password": "padme_amidala"
}

Response

Response takes 3 different response codes.

If loggin success, returns 200 with JWT Token in Authorization header.

If request is invalid, returns 400.

If email or password incorrect, returns 401.

Response with 200 status code

{
    "message": "Login success"
}

/logout [GET]

Actually, logout endpoint does nothing. It sends only 200 response without Authorization header whether user logged in or not.

/ [GET]

/ endpoint is the test endpoint for authentication. If you send a valid JWT Token in Authorization header, you get a response with 200 status code like this:

{
    "message": "welcome, Anakin"
}

If you send a invalid JWT Token in Authorization header, you get a response with 401 status code like this

{
    "message": "Login required"
}

About

Flask and sqlalchemy authentication boilerplate

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published