Home

Awesome

start-fastapi

Version 2021, based on FastAPI, an easy-to-use web app developed upon Starlette Framework

Requirements

Structure

The web application is based on onion style~

onion

The directory structure is:

Quick Start

Launch App Server

Run ./main.py to start the example, which includes:

The internal steps are:

You can put your launch scripts inside ./misc/build for your different launch options

Coding Guide

To build your logic, common steps are follows:

Some tips for coding:

HTTP Response

Most of the handled requests should contain a status code of 200

A simple solution is to use Resp model in ./core/model/handler.py to generate response body for your handlers

{
  "success": bool,
  "message": str,
  "code": IntEnum,
  "data": Any,
}

Use Resp.ok to generate success response and use Resp.err to generate error response

Misc

WebSocket

The test handler ./app/handler/test.py contains ws handler examples

To know more about it, see websocket documentation

Deployment

Run ./misc/build/pack.sh to pack the project into ./misc/build/start-fastapi.tar.gz

See ./misc/build/Dockerfile for an example of docker deployment