Skip to content

A Simple CURD application using Python, FastAPI, SQL Server

Notifications You must be signed in to change notification settings

Jeevanebi/python-curd-fastAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI CRUD Application with SQL Server

This project is a simple CRUD (Create, Read, Update, Delete) application built using FastAPI, pyodbc, and SQL Server. The application allows you to manage user records in a SQL Server database.

Table of Contents

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/your-repository.git
    cd your-repository
  2. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
  3. Install the required packages:

    pip install fastapi uvicorn pyodbc

Setup

  1. Configure the database connection:

    Update the connection_string in main.py with your SQL Server details.

    server = 'your_server'
    database = 'TestDB'
    username = 'your_username'
    password = 'your_password'
    connection_string = f'DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={server};DATABASE={database};UID={username};PWD={password}'
  2. Ensure your SQL Server database has the necessary table:

    CREATE TABLE test (
        EmpID INT PRIMARY KEY,
        Name NVARCHAR(100),
        Address NVARCHAR(100),
        Phone NVARCHAR(15)
    );

Running the Application

Start the FastAPI application using Uvicorn:

uvicorn main:app --reload

This will start the application and make it available at http://127.0.0.1:8000.

API Endpoints

Create User

  • URL: /users/
  • Method: POST
  • Request Body:
    {
        "empId": 1,
        "name": "John Doe",
        "address": "123 Main St",
        "phone": "123-456-7890"
    }
  • Response:
    {
        "message": "User created successfully"
    }

Read User

  • URL: /users/{id}
  • Method: GET
  • Response:
    {
        "EmpId": 1,
        "Name": "John Doe",
        "Address": "123 Main St",
        "Phone": "123-456-7890"
    }

Update User

  • URL: /users/{id}
  • Method: PUT
  • Request Body:
    {
        "name": "John Doe",
        "address": "123 Main St",
        "phone": "123-456-7890"
    }
  • Response:
    {
        "message": "User updated successfully"
    }

Delete User

  • URL: /users/{id}
  • Method: DELETE
  • Response:
    {
        "message": "User deleted successfully"
    }

Dependencies

License

This project is licensed under the MIT License.

About

A Simple CURD application using Python, FastAPI, SQL Server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages