Dynamic API - New feature available (PRO starters)

Dynamic API allows exposing via DRF a new model using minimal coding - a feature available for PRO starters.

Dynamic API - A new feature provided by AppSeed (all PRO Starters)
Dynamic API - A new feature provided by AppSeed (all PRO Starters)

Hello Coders! This article presents Dynamic API, the latest feature available for the Django Datta PRO starter and soon available for all related Django PRO starters. This pattern allows exposing an API interface over any model used in the project with a minimal coding interaction. Here are the steps:

  • 👉 1# - Define your model in apps/models.py
  • 👉 2# - Enable the model in the configuration
  • 👉 3# - Migrate the project

Step 2 is introduced to empower the developer to filter exposed models with ease. Once the above steps are finished, the CRUD operations (Create, Read, Update, Delete) are available via localhost/api/<MODEL_NAME>/ URI.

The first starter updated with this feature is Django Datta Able PRO using a simple Books model defined as below:

class Books(models.Model):
    class Meta:
        app_label = 'dyn_api'

    title    = models.CharField(max_length=100)
    year     = models.IntegerField(default=2020)
    comments = models.CharField(max_length=512) 
Dynamic API - Books Model Definition

As mentioned before, the model exposure in the DRF interface should be enabled in the configuration.

    # pattern:
    'endpoint': 'Model',
    'books'   : "Books",   # <-- Model managed by the Dynamic API
    #'sales'  : "Sales",   # <-- Model Ignored
Dynamic API - App Configuration

At this point, we need to migrate the project using the classic commands:

$ python manage.py makemigrations
Migrations for 'dyn_api':
    - Create model Books
And the migrate command:
python manage.py migrate       
Operations to perform:
  Apply all migrations: dyn_api
Running migrations:
  Applying dyn_api.0001_initial... OK

To interact with the API we can use POSTMAN or the default DRF Interface.

Dynamic API - DRF Interface

To see the service in action for Books model, please access the links:

Dynamic API - Provided by Datta Able PRO Django
Dynamic API - Provided by Datta Able PRO Django

Thanks for reading! For more resources, feel free to access: