Giter Site home page Giter Site logo

fastblog's Introduction

FastBlog

Demo blog API built with FastAPI

Environment

Environment is managed with pipenv. Hence, to install all the required packages specified in the Pipfile, run

pipenv install

Running the Server

To run the server localy, use uvicorn:

uvicorn app.main:app --reload

Testing

Tests are written using pytest. Just run

python -m pytest

from the project directory to execute all the tests.

Implementation Notes

  • The API works with a fake database, which is just a Python class with no persistency. This FakeDb emulates very bare-bones database:
    • Rows inserted using a model class
    • Basic functions such as add, get, get_all, delete, and update
  • The application could have been much shorter if I didn't create an entire fake database module. Instead, I could have used pydantic models exclusively and saved their json representation into a map. However, I felt that in that case the project would be too small and not really representative of real world applications. In this form, on the other hand, it demonstrates how an API would communicate with a SQL database
  • Normally, I wouldn't be manipulating the blog post data directly in the main.py function, but instead there would be a separate crud module. However, since the FakeDb in database.py behaves pretty much like a crud module, I decided against creating this unnecessary module
  • In real world some of the main api functions should be async. However, since in this demo we were dealing with a fake database that doesn't even perform any IO operations, async is not necessary

fastblog's People

Contributors

rahlir avatar

Watchers

James Cloos avatar  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.