# Unleash FastAPI <!-- Put the link to this slide here so people can follow --> slide: https://hackmd.io/@ogarcia/fast-api ![](https://hackmd.io/@ogarcia/fastapi) repo: https://github.com/leticiapb80/hero-app-template --- This is a workshop so, please prepare laptop or smartphone to join! --- ## :wave: Who am I? - Leticia Perrino - :email: `leticia.perrino@gmail.com` - Back-end developer - VSCode :heart: - I use tabs. :cat: --- ## :punch: Main goal Build modern microservices in Python with a high performance and asyncronous support DRF is really great but... too heavy, so... --- ## :hot_pepper: Main Tecnologies used - **[FastAPI](https://fastapi.tiangolo.com/)**: A modern, fast (high-performance), web framework for building APIs - **[Pydantic](https://docs.pydantic.dev/1.10/)**: Data validation and settings management - **[SQLModel](https://sqlmodel.tiangolo.com/)**: Library for interacting with SQL databases (it depends on **[SQLALchemy]((https://www.sqlalchemy.org/))**, Python SQL toolkit and ORM) - **[Alembic](https://alembic.sqlalchemy.org/en/latest/)**: A lightweight database migration tool for usage with the SQLAlchemy --- ## :clipboard: Overview Pros: - API doc integrated (swagger) - Async support - Great framework documentation - Free database to choose - Dependency Injection support - Data validation and serialization Cons: - Free database to choose - Develop tools must be created or dependencies (shell, admin portal, ORM...) - Well-design code and architecture must be defined or you will get a great :spaghetti: - Not support singleton using its DI --- ## :left_right_arrow: Our comparative | Feature | DRF | FastAPI | | ------------------------------- | ------------------ |:-------------------------------------------------------------------------------------------------- | | CBV | :white_check_mark: | Supported with external aid ([fastapi-utils](https://fastapi-utils.davidmontague.xyz/)) | | Data Serializing and validation | :white_check_mark: | :white_check_mark: | | DB integration | :white_check_mark: | You choose | | Swagger/OpenAPI integration | :x: | :white_check_mark: | | Authentication | :white_check_mark: | :white_check_mark: | | Data pagination | :white_check_mark: | Supported with external aid ([fastapi-pagination](https://uriyyo-fastapi-pagination.netlify.app/)) | --- ## Hero app manager (1) - Main structure ![Main structure](https://hackmd.io/_uploads/HJU1mIxGT.png) - Basic core ![Basic core](https://hackmd.io/_uploads/S1f4QIgzp.png) --- ## Hero app manager (2) - Api core and views ![Api core and views](https://hackmd.io/_uploads/Bkox_8lza.png) - Core services and validation schemas ![Core services and validation schemas](https://hackmd.io/_uploads/S1TIdLxfp.png) --- ### Layers architecture ![Arquitectura](https://hackmd.io/_uploads/BygKHvlfT.jpg) --- ### Basic steps - TODO Descargar el proyecto base - Crear un entorno virtual e instalar las dependencias - TODO Ejecutar las migraciones - TODO Probar a arrancar el servidor de FastAPI - A fluir --- {%youtube E8Nj7RwXf0s %} --- ### Usage flow --- ```graphviz digraph { compound=true rankdir=RL graph [ fontname="Source Sans Pro", fontsize=20 ]; node [ fontname="Source Sans Pro", fontsize=18]; edge [ fontname="Source Sans Pro", fontsize=12 ]; subgraph core { c [label="Hackmd-it \ncore"] [shape=box] } c -> sync [ltail=session lhead=session] subgraph cluster1 { concentrate=true a [label="Text source\nGithub, Gitlab, ..."] [shape=box] b [label="HackMD Editor"] [shape=box] sync [label="sync" shape=plaintext ] b -> sync [dir="both"] sync -> a [dir="both"] label="An edit session" } } ``` --- ### Architecture of extension --- ![](https://i.imgur.com/ij69tPh.png) --- ## Content script - Bind with each page - Manipulate DOM - Add event listeners - Isolated JavaScript environment - It doesn't break things --- # :fork_and_knife: --- <style> code.blue { color: #337AB7 !important; } code.orange { color: #F7A004 !important; } </style> - <code class="orange">onMessage('event')</code>: Register event listener - <code class="blue">sendMessage('event')</code>: Trigger event --- # :bulb: --- - Dead simple API - Only cares about application logic --- ```typescript import * as Channeru from 'channeru' // setup channel in different page environment, once const channel = Channeru.create() ``` --- ```typescript // in background script const fakeLogin = async () => true channel.answer('isLogin', async () => { return await fakeLogin() }) ``` <br> ```typescript // in inject script const isLogin = await channel.callBackground('isLogin') console.log(isLogin) //-> true ``` --- # :100: :muscle: :tada: --- ### Wrap up - Cross envornment commnication - A small library to solve messaging pain - TypeScript Rocks :tada: --- ### Thank you! :sheep: You can find me on - GitHub - Twitter - or email me
{"title":"Talk slides template","description":"View the slide with \"Slide Mode\".","contributors":"[{\"id\":\"93855254-5bcf-438a-b2d1-f9f805e036e4\",\"add\":2602,\"del\":106},{\"id\":\"8c2b262f-e566-4ed4-aad0-9d4c6112d5c0\",\"add\":3739,\"del\":588}]"}
    296 views