Coder Social home page Coder Social logo

generic-dashboard-imc-backend's Introduction

Generic BMI Template API (Django, Django REST Framework, PostgreSQL)

Overview

This API utilizes the robust Django framework and the versatile Django REST Framework to provide a well-structured and documented template for calculating Body Mass Index (BMI) and managing person data. It's meticulously designed to be adaptable to your specific requirements and integration needs, offering a solid foundation for further development.

Prerequisites:

Dependencies:

  • You'll need to install the required dependencies in your virtual environment (venv):

    python -m venv venv
    source venv/bin/activate
    pip install django djangorestframework

Endpoints:

Path HTTP Method Description
/admin/ GET Access to Django admin site (requires authentication)
/healthcheck/ GET Returns a simple response to verify API health and uptime
/person/ GET/POST Retrieves a list of persons with basic information / Create a person in Database
/person/<int:id>/ GET/PUT/DELETE Retrieves detailed information for a specific person by ID / Updates a person / Deletes a person
/person/peso-ideal/<int:id>/ GET Calculates and returns the ideal weight for a person by ID

Authentication:

  • The /admin/ endpoint necessitates Django authentication and authorization for access.
  • Other endpoints are currently public but could be secured with appropriate mechanisms as needed.

Request and Response Formats:

  • Requests and responses adhere to the JSON (JavaScript Object Notation) format for clear and consistent data exchange.
  • Dates and times should be sent in a standard format like ISO 8601 (e.g., 2024-02-10T00:32:00Z) for global understandability.
  • Request bodies must comply with the expected schema for each endpoint to ensure correct data interpretation.
  • Response bodies will contain an HTTP status code and relevant data in JSON format for easy handling.

Fields:

Field Type Description
id integer Unique identifier for the person
nome string Person's full name
data_nasc date Person's date of birth
cpf string Person's CPF (Cadastro de Pessoas Físicas) number (Brazil-specific)
sexo string Person's gender (e.g., 'M', 'F')
altura float Person's height in meters
peso float Person's weight in kilograms

BMI Calculation:

  • The /person/peso-ideal/<int:id>/ endpoint utilizes the standard BMI formula: BMI = peso / (altura * altura).
  • BMI provides a general indication of weight-for-height status, but it's not a definitive measure of health. Consult a healthcare professional for personalized guidance.

Example Usage (Python):

import requests

# Ensure you're in the activated virtual environment

response = requests.get('http://localhost:8000/person/')
data = response.json()

print(data)  # Outputs a list of person objects

person_id = 123
response = requests.get(f'http://localhost:8000/person/{person_id}/')
data = response.json()

print(data)  # Outputs details of the person with ID 123

response = requests.get(f'http://localhost:8000/person/peso-ideal/{person_id}/')
data = response.json()

print(data)  # Outputs the calculated ideal weight for the person

Additional Notes:

  • This template serves as a foundation, and you may need to customize it based on your specific requirements.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.