Repository navigation
Releases: GitauHarrison/api_in_flask
Release list
v8.0.0-api-friendly-error-response
Allow a client to determine the format they'd prefer for error responses, be it JSON or HTML.
v7.0.0-token-authentication
Protect API endpoints as the web client protects select pages from anonymous access.
- Generate tokens
- Add token expiration to improve security
- Revoke the token if needed instead of relying entirely on the expiration time
Basic authentication requires that a client provide a user's username and password in the request. The user's credentials are base64 encoded and the result is added to the Authorization header sent by the client.
The server will then create a token for the selected user. Now, this user can be verified based on their token. A 401 Unauthorized error response will be generated if there is no such user.
To protect endpoints, add token_auth.login_required. The decorator comes from Flask-HTTPAuth.
With the user authenticated and authorized, each protected endpoint can be accessed by adding the selected user's token in the Authorization header as Authorization: Bearer < token >.
v6.0.0-user-endpoints
- Install HTTPie to work with endpoints via the command-line
- Register user
- Make a post as a registered user
- Modify user and post data
- Delete user and post data
v5.0.0.0-handle-api-errors
The "400 Bad Request" error is the most common API error. It comes about when a client sends a request with invalid data. Create a dedicated method used to handle this type of error.
The error message contains a short description of the error, plus an optional error message.
{
"error": "short error description",
"message": "error message"
}Flask should return a JSON response to the error.
v4.0.0-resource-representation
- Define a generic mixin class that is used to return a collection of resources
- Inherit the mixin class in
UserandPostmodels - Links generated so generically to ensure it is dependant on the request
v3.0.0-api-blueprint
Added an api blueprint. It has the following modules:
users: access to user resourcesposts: access to posts resourceserrors: error responsestokens: API authentication
v1.0.0-basic-app
This version features a very basic Flask app:
- Default anonymous pages (
loginandregister.html) - Pages requiring a user to sign in ('index.html
,profile.html,edit_profile.html`) - Models:
UserandPost
User model columns
-
id -
username -
email -
last_seen -
password -
timestamp
Post model columns
-
id -
title -
body -
timestamp