Skip to content

Here is an example API using Django School & Students

Notifications You must be signed in to change notification settings

wichai-t/django-api-example

Repository files navigation

API School & Students example

Hi! this is my example School & Students API using Django Rest Framework (DRF). It focuses on simplicity and practically implementation.

Try it!

https://school-demo.wichai.site

Test

All test cases are inside school_manager/tests directory.
Run all tests using python manage.py test

Deployment

You can deploy the app on system environment or a docker environment.
NOTE: The Postgis is required on your system.

Docker

To build a docker image and run the container, follows these steps:

  1. Clone or download this repo.
    $ git clone [email protected]:wichai-t/django-api-example.git
  2. Set secrets and other configs in the .env file.
  3. Build the image.
    $ docker build -t school_man:latest -f Dockerfile .
  4. Run a container.
    $ docker run --name myschoolman -p 8080:8000 school_man

Then check the result on the web site: 127.0.0.1:8080

Working log

Here is the working log as I am writing this project:

Date Task Detail
Sat, 15 Jan 22 Setting up the project
  1. Create a Django app, with:
    • Postgres as a database
    • Pipenv as a Python dependency manager.
    • Environment file (for sensitive information, etc.)
  2. Add models to create the following structure:
    • Students have a first name, a last name, and a student identification string (20 characters max for each)
    • Schools have a name (20 char max) and a maximum number of student (any positive integer)
    • Each student object must belong to a school object
    Implementing Django Rest Framework (DRF) support Make sure the API is following these:
    • Endpoint /students/ will return all students (GET) and allow student creation (POST)
    • Endpoint /schools/ will return all schools (GET) and allow school creation (POST)
    • Endpoint /schools/:id and /students/:id will return the object by :id (GET) and allow editing (PUT/PATCH) or deleting (DELETE)
    • Student creation will generate a unique identification string
    • If maximum number of student in a school reached, it will return a DRF error message
    Sun, 16 Jan 22 Implementing the Django Nested Routers support Install the Django Nested Routers and Make sure the API is following these:
    • Endpoint /schools/:id/students will return students who belong to school :id (GET)
    • Endpoint /schools/:id/students will allow student creation in the school :id (POST)
    • Config the endpoint to allow GET/PUT/PATCH/DELETE methods on /schools/:id/students/:id
    • Config the endpoint to respect the same two last rules of the above detail
    Improve readability
    • Make the code tidier
    • Writing docstring
    • and this README.md
    Add all test cases Inside the school_manager/tests directory.
    Modify some features
    • Add some fields to the models: education stage to Student and location (Postgis lat, lon) to Schools
    • Add search and ordering filters to the endpoints such as /students/?search=jeremy&ordering=first_name
    • Make admin's url configurable via the env file
    • Config Limit-Offset style pagination
    Mon, 17 Jan 22 Implement the JWT authentication API support Install the djangorestframework-jwt and config its routes
    Dockerize the application Add Dockerfile to project
    Deploy Deploy the project on https://school-demo.wichai.site
    Generate example data
    • Create a demo data generator fn inside the tests dir
    • Generate example data on the site
    Add home page Simple json response, which shows our API urls

    About

    Here is an example API using Django School & Students

    Resources

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published