Git Product home page Git Product logo

hngx_task2's Introduction

FastAPI CRUD API with SQLAlchemy and SQLite

This FastAPI CRUD API provides endpoints to perform CRUD (Create, Read, Update, Delete) operations on user records using SQLAlchemy and SQLite as the database.

Table of Contents

Prerequisites

Before you can set up, run, and use the API, make sure you have the following prerequisites installed:

  • Python 3.x
  • pip (Python package manager)

Getting Started

  1. Clone the repository:

    git clone <repository-url>
    cd <repository-folder>
  2. Install the required Python packages:

    pip install -r requirements.txt

API Endpoints

Create a User

  • URL: /api/
  • Method: POST
  • Request Body: JSON
    {
      "name": "mark essien"
    }
  • Response: JSON
    {
      "id": 1,
      "name": "mark essien"
    }

Read All Users

  • URL: /api/
  • Method: GET
  • Query Parameters:
    • skip (optional): Number of records to skip (default: 0)
    • limit (optional): Maximum number of records to return (default: 100)
  • Response: JSON Array of Users

Read a User by ID

  • URL: /api/{user_id}/
  • Method: GET
  • Response: JSON
    {
      "id": 1,
      "name": "mark essien"
    }

Update a User by ID

  • URL: /api/{user_id}/
  • Method: PUT
  • Request Body: JSON
    {
      "name": "Updated Name"
    }
  • Response: JSON
    {
      "id": 1,
      "name": "Updated Name"
    }

Delete a User by ID

  • URL: /api/{user_id}/
  • Method: DELETE
  • Response: JSON
    {
      "id": 1,
      "name": "Updated Name"
    }

Running the API

To run the API, execute the following command in the project directory:

uvicorn main:app --reload

The API will be available at http://127.0.0.1:8000/. You can access the Swagger documentation at http://127.0.0.1:8000/docs and the ReDoc documentation at http://127.0.0.1:8000/redoc.

Sample Requests

Here are some sample requests you can make to the API:

  • for local server, replace "https://hngx-task2-qh6l.onrender.com" with "http://127.0.0.1:8000"

  • Create a User:

    curl -X POST -H "Content-Type: application/json" -d '{"name": "mark essien"}' https://hngx-task2-qh6l.onrender.com/api/
  • Read All Users:

    curl https://hngx-task2-qh6l.onrender.com/api/
  • Read a User by ID:

    curl https://hngx-task2-qh6l.onrender.com/api/1/
  • Update a User by ID:

    curl -X PUT -H "Content-Type: application/json" -d '{"name": "Updated Name"}' https://hngx-task2-qh6l.onrender.com/api/1/
  • Delete a User by ID:

    curl -X DELETE https://hngx-task2-qh6l.onrender.com/api/1/

Known Limitations

  • This API uses an SQLite database, which may not be suitable for large-scale production use. Consider using a more robust database system for production deployments.
  • This is a basic CRUD API and may require additional features and security measures for real-world applications.

hngx_task2's People

Contributors

preciousajorgba 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.