Giter Site home page Giter Site logo

oskccy / python_rest_api Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 13.47 MB

user data REST API, built with SQLAlchemy, Python libs & Flask

Python 99.70% PowerShell 0.05% Shell 0.02% C 0.04% Cython 0.11% JavaScript 0.05% CSS 0.03%
flask python sql sqlalchemy-orm

python_rest_api's Introduction

Python REST API with Flask and SQLAlchemy

This is a simple RESTful API implementation using Flask and SQLAlchemy that provides CRUD operations for a User model.

Screenshot 2023-08-21 at 1 30 19 AM

Table of Contents

Setup and Installation

  1. Ensure you have Flask and Flask-SQLAlchemy installed. If not, install them via pip:

    pip install Flask Flask-SQLAlchemy
    
  2. Clone this repository and navigate to its directory.

  3. Run the main server file to start the application.

Database Configuration

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.

Routes

Root Route

  • URL: /
  • Method: GET
  • Description: A simple route to check if the server is running.
  • Response: Returns a string "Hello World!".

Fetch All Users

  • URL: /users
  • Method: GET
  • Description: Retrieves all the users from the database.
  • Response: Returns a list of users in JSON format.

Fetch User by ID

  • URL: /users/<id>
  • Method: GET
  • Description: Retrieves a single user based on its ID.
  • Response: Returns the user details in JSON format.

Add a New User

  • URL: /users
  • Method: POST
  • Data Params: JSON object with user details.
screenshot
{
  "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.

Delete User by ID

  • URL: /users/<id>
  • Method: DELETE
  • Description: Deletes a user based on its ID.
  • Response: Confirmation of deletion with the deleted user's ID.
Screenshot 2023-08-21 at 1 35 55 AM

Data Fetcher

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.

Contributions

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:

  1. Fork the Repository: If you're interested in making changes, start by forking this repository.

  2. Clone and Create a New Branch: Clone your fork to your local machine and create a new branch for your suggestions or fixes.

  3. Commit Changes: Make your modifications and commit your changes. Aim to have clear and descriptive commit messages.

  4. Pull Request: Create a pull request to this repository. Provide a brief overview of the changes you've made.

python_rest_api's People

Contributors

oskccy avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

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.