A simple RESTful API built with Flask that allows saving user data into a SQL Server database using pyodbc.
- Exposes a POST endpoint
/SaveDatato store data. - Accepts
firstNameandlastNameas JSON payload. - Connects to SQL Server database via
pyodbc. - Includes error handling and clear response messages.
- Runs locally with Flask, easy to extend for production.
- Python 3
- Flask
- SQL Server
- pyodbc
-
Clone the repository:
git clone https://github.com/yourusername/SaveDataAPI.git cd SaveDataAPI -
Create a virtual environment and install dependencies:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt
-
Update database connection string in
app.py:connection_string = "DRIVER={ODBC Driver 17 for SQL Server};SERVER=localhost;DATABASE=yourDB;UID=yourUser;PWD=yourPassword"
-
Run the server:
flask run
Send a POST request to /SaveData with JSON body:
{
"firstName": "John",
"lastName": "Doe"
}curl -X POST http://127.0.0.1:5000/SaveData \\
-H "Content-Type: application/json" \\
-d '{"firstName": "John", "lastName": "Doe"}'{
"status": "success",
"message": "Data saved successfully!"
}.
├── app.py # Main Flask application
├── requirements.txt # Python dependencies
└── README.md # Project documentation
- Add GET endpoints to fetch saved data.
- Add authentication & authorization.
- Containerize with Docker.
- Deploy on cloud (AWS / Azure).