This is a simple RESTful API implementation using Flask and SQLAlchemy that provides CRUD operations for a User
model.
-
Ensure you have Flask and Flask-SQLAlchemy installed. If not, install them via pip:
pip install Flask Flask-SQLAlchemy
-
Clone this repository and navigate to its directory.
-
Run the main server file to start the application.
The database is configured using SQLAlchemy ORM with SQLite. The current configuration uses a local SQLite database named data.db
. The User table/model consists of fields like id
, first_name
, last_name
, phone_number
, social_insurance
, and credit_card
.
Note: The credit card and social insurance numbers should be encrypted before being stored in the database.
- URL:
/
- Method:
GET
- Description: A simple route to check if the server is running.
- Response: Returns a string "Hello World!".
- URL:
/users
- Method:
GET
- Description: Retrieves all the users from the database.
- Response: Returns a list of users in JSON format.
- URL:
/users/<id>
- Method:
GET
- Description: Retrieves a single user based on its ID.
- Response: Returns the user details in JSON format.
- URL:
/users
- Method:
POST
- Data Params: JSON object with user details.
{
"first_name": "Devin",
"last_name": "Dubb",
"phone_number": "1234567890",
"social_insurance": "XYZ123",
"credit_card": "1234-5678-9012-3456"
}
- Description: Adds a new user to the database.
- Response: Returns the added user details in JSON format.
- URL:
/users/<id>
- Method:
DELETE
- Description: Deletes a user based on its ID.
- Response: Confirmation of deletion with the deleted user's ID.
There's an additional script that fetches random user data from an external API. This script uses the requests
module to make a GET request and fetch data for 2 random users.
To run this script, ensure you have the requests
module installed:
pip install requests
Run the data fetcher script to get random user data.
While this is primarily a solo project, feedback, suggestions, or pull requests are always appreciated. If you find any bugs or see room for improvement, please feel free to fork the repository, make your changes, and initiate a pull request.
Steps to Contribute:
-
Fork the Repository: If you're interested in making changes, start by forking this repository.
-
Clone and Create a New Branch: Clone your fork to your local machine and create a new branch for your suggestions or fixes.
-
Commit Changes: Make your modifications and commit your changes. Aim to have clear and descriptive commit messages.
-
Pull Request: Create a pull request to this repository. Provide a brief overview of the changes you've made.