Coder Social home page Coder Social logo

ecom-backend's Introduction

A sample backend application in FastAPI, Python and MongoDB

Installation

git clone https://github.com/me-heer/ecom-backend.git
cd ecom-backend
pip3 install -r requirements.txt
uvicorn main:app

After uvicorn main:app, the server runs on http://127.0.0.1:8000.

Copy and paste the sample curl calls below and test the output.

You don't need to install MongoDB, since this app will connect to a test instance of MongoDB Atlas with sample data. The connection string of MongoDB is purposefully pushed to this repository for ease of access while testing this.

Sample API Calls

Get Products

curl -X GET --location "http://127.0.0.1:8000/products?limit=3&min_price=15&max_price=25" \
    -H "Accept: application/json"

Create Orders

curl -X POST --location "http://127.0.0.1:8000/orders" \
    -H "Content-Type: application/json" \
    -d '{
          "items": [
            {"product_id": "65b77503b064d441b7d4c2b7", "bought_quantity": 1}
          ],
          "user_address": {
            "city": "Mumbai",
            "country": "India",
            "zip_code": "12345"
          }
        }'

Future Enhancements

Ideally, I would like to have the following things in a project, but since this was a sample project, I refrained from working on them due to time constraints:

  1. Unit/Integration/End-to-end tests
  2. When new orders are created, we should be using locks/mutexes or other techniques to prevent race conditions.
  3. When the scale of this project grows, use N-tier architecture (Controller -> Service -> Repository)
  4. Move MongoDB configurations to its own file
  5. Use Pydantic Model Validations instead of manual code
  6. Logging
  7. Remove .env file from the repository (I have just kept it so that anyone can run this)
  8. API Documentation (i.e.: Swagger)
  9. Authentication/Authorisation (of course)
  10. Rate Limiting
  11. More Validations

ecom-backend's People

Contributors

me-heer 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.