Project Review: Django API Endpoints

API endpoints for the Django Blog Project

Summary

Introduction

The Django blog also has some REST API endpoints that can be used by a front-end developer to render the fields with a framework such as React, Vue, Angular, or Ember.

Naturally, the implementation of these endpoints is a highly contrived example for portfolio demonstration purposes.

Features

  • Browsable API list page for all of the posts (paginated by 3 posts per page)
  • Browsable API detail page for an individual post
  • The standard template supplied by Django Rest Framework has been overridden so the colours are consistent with portfolio's theme colours
  • Navigation icons from Font Awesome have been added
  • Time is purposefully left in its database storage format so that a front-end developer can use a JavaScript library such as Moment.js which can format the time according to each user's locale
  • Fields from downstream models included
  • Properties from models are included as fields
  • I purposefully have not provided a POST form within the browsable API as I do not want people or bots to post to the database

Objectives

I set out to build a browsable API endpoint that would enable front-end developers to render the fields from the application using their chosen front-end framework such as React, Vie, Angular or Ember.

The Approach & Solution

My starting point was to research the setting of the endpoints using serializers.

Additional research was required for some of the less frequently used aspects of creating an API such as rendering properties that have been defined against a model, or fields that have been defined in a downstream model.

The implementation differs for the various relationships between database tables. Within the blog project, there are examples of all of the main database join types: one-to-one, one-to-many, and many-to-many.

Evaluation

I would like investigate documenting the API using something like Swagger. There are also some small customisations that I would like to make to the base template with regards to titling and descriptions.

Languages, Technologies & Skills Used

In approximate order of frequency used...
Languages: Python, HTML / CSS, Bootstrap, Font Awesome
Frameworks / Services: Django, Django REST Framework
Software: VS Code
Libraries: N/A
Notable Packages: N/A
Infrastructure: GitHub, Docker, Poetry