Skip to content

Releases: GitauHarrison/api_in_flask

v8.0.0-api-friendly-error-response

Choose a tag to compare

Allow a client to determine the format they'd prefer for error responses, be it JSON or HTML.

v7.0.0-token-authentication

Choose a tag to compare

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

Choose a tag to compare

  • 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

Choose a tag to compare

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

Choose a tag to compare

  • Define a generic mixin class that is used to return a collection of resources
  • Inherit the mixin class in User and Post models
  • Links generated so generically to ensure it is dependant on the request

v3.0.0-api-blueprint

Choose a tag to compare

Added an api blueprint. It has the following modules:

  • users: access to user resources
  • posts: access to posts resources
  • errors: error responses
  • tokens: API authentication

v1.0.0-basic-app

Choose a tag to compare

@GitauHarrison GitauHarrison released this 12 Oct 23:17

This version features a very basic Flask app:

  • Default anonymous pages (login and register.html)
  • Pages requiring a user to sign in ('index.html, profile.html, edit_profile.html`)
  • Models: User and Post

User model columns

  • id
  • username
  • email
  • last_seen
  • password
  • timestamp

Post model columns

  • id
  • title
  • body
  • timestamp