Code Monkey home page Code Monkey logo

fastapi-blog's Introduction

Test

A FastAPI sample

It's a FastAPI implementation as the backend for a blog system. This project's a funny goal to apply things that I'm learning. Things that you see here like telemetry using open source projects, CRUD using REST, and GraphQL (I hope that I have time to do that).

Dependencies

  • Poetry
  • SQLAlchemy
  • Alembic for migrations
  • OpenTelemtry for instrumentation
  • Docker
  • Docker-Compose
  • Jaeger
  • Next.js
  • React
  • Make

How to use

Use make command to run inside a docker container, it'll expose the port 8000 and access using URL: http://localhost:8000. I'm not sure if a makefile runs in the Powershell, probably yes but I suggest using WSL2.

The frontend is in the early stage but you can see access: http://localhost:3000/.

Up and run:

make dev-up

"Screenshot with REST backend endpoints"

This repo is instrumented by OpenTelemtry and export metric to Jaeger that starts together with the app by Docker-Compose, to access: http://localhost:16686/

Tests

To run tests will up a PostgreSQL container and expose 5433 port to populate. The report will write in htmlcov dir.

make test-app

Run and watch on the Jaeger things breaking

The FastAPI code here was OpenTelemetry instrumented and to export Traces to Jaeger. If you want to see a break simulation, follow the steps below.

Install dependencies

python -m venv .venv

pip install poetry

poetry install

Start FastAPI, PostgreSQL and Jaeger

make dev-up

asciicast

Open another shell session and run populate_posts.py to create users and posts samples.

opentelemetry-instrument tests/populate_posts.py

asciicast

Break things

Open a third shell session to stop Postgres, this will break the FastAPI app. You'll see error messages in the log and the script client on the console. Stop Postgres, wait some seconds or a minute, start Postgres again.

make dev-db-kill

sleep 30

make dev-db-start

asciicast

Stop populate script

Stop the populate_posts.py scritpt (ctrl+c), go to Jaeger UI (http://localhost:16686/). If everything fine (or fail... ๐Ÿ˜), you'll see on Jaeger like screenshots below.

  • FastAPI errors exported by OpenTelemetry to Jaeger

"jaeger traces errors"

  • An error detail from the client request and server.

"an example of errors in the jaeger"

Known issues

  • Some Opentelemetry warnings will show when tests ran.

TODO

  • Pagination
  • CORS
  • Token authentication
  • GraphQL
  • Improve Token
  • SAML/Oauth2
  • Run tests in container
  • Autentication
  • Implement UI (React)
  • Helm Chart
  • Improvement tests with tox
  • Implement a default path (/)
  • Custom Limit and Offset
  • Add script to ingest samples
  • CI tests

fastapi-blog's People

Contributors

adriangb avatar dependabot[bot] avatar fike avatar ph47s74x avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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