Skip to content
This repository was archived by the owner on Jun 15, 2024. It is now read-only.
/ python-flask-demo Public archive

This is a simple Flask application for learning CRUD operations at a foundational level. It defines several REST endpoints to carry out operations. It stores data in a simple relational database with one model (defined using SQLAlchamy).

Notifications You must be signed in to change notification settings

mbeps/python-flask-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a simple Flask application for learning CRUD operations at a foundational level. It defines several REST endpoints to carry out operations. It stores data in a simple relational database with one model (defined using SQLAlchamy).

Requirements

  • Python 3.11
  • Poetry

API Endpoints

1. GET /contacts

  • Description: Retrieves all contacts from the database.
  • Returns: JSON list of all contacts.

2. POST /create_contact

  • Description: Creates a new contact.
  • JSON Body Required:
    {
      "firstName": "First Name",
      "lastName": "Last Name",
      "email": "email@example.com"
    }
  • Returns: Message indicating if the user was created or if an error occurred.

3. PATCH /update_contact/<int:user_id>

  • Description: Updates an existing contact.
  • Parameters: user_id - The ID of the contact.
  • JSON Body (Optional Fields):
    {
      "firstName": "New First Name",
      "lastName": "New Last Name",
      "email": "new.email@example.com"
    }
  • Returns: Message indicating if the user was updated or if the user was not found.

4. DELETE /delete_contact/<int:user_id>

  • Description: Deletes a contact.
  • Parameters: user_id - The ID of the contact.
  • Returns: Message indicating if the user was deleted or if the user was not found.

Tech Stack

  • Python: A versatile programming language that is easy to learn and powerful in execution. It's used for all backend logic.

  • Poetry: A tool for dependency management and packaging in Python. It helps manage libraries and dependencies with ease and reproducibility.

  • Flask: A lightweight and flexible Python web framework. It provides tools and features to create and deploy web applications quickly.

  • SQLAlchemy: A SQL toolkit and Object-Relational Mapping (ORM) system for Python. It allows the application to communicate with the database using Python code instead of SQL.

Usage

Install Dependencies

Install project dependencies using Poetry CLI:

poetry install

This will automatically create a virtual environment.

Run Project

Use Poetry to run the project locally:

poetry run python main.py

Will start the server at localhost:5000

About

This is a simple Flask application for learning CRUD operations at a foundational level. It defines several REST endpoints to carry out operations. It stores data in a simple relational database with one model (defined using SQLAlchamy).

Topics

Resources

Stars

Watchers

Forks

Languages