cympfh / fastsvelte

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FastSvelte = FastAPI + Svelte

A Template for Single-page App using FastAPI + Svelte

Why?

  • FastAPI
    • Typed & Fast Way to build a API Server using Python
  • Svelte
    • Fast & Easy to Modern Front-end
    • and supporting TypeScript!

Start up Sample Project

Clone this, then

# on local
make build
make serve
# on docker
make build-docker
make serve-docker

And open localhost:8080.

Development

Server Side (Python/FastAPI)

Check ./server.py

# Define API functions
@app.get("/api/greeting")
def greeting(name: Optional[str] = None):
    """Greeting you"""
    if name:
        return {"msg": f"Hello {name}!"}
    return {"msg": "Hi!"}

# URLs other than APIs are
# - static files under `web/public` if exists
#    - /aaa/bbb -> `./web/public/aaa/bbb`
# - Returns `web/public/index.html` else
#    - SPA on Front-end side
app.mount("/", MountFiles(directory="web/public", html=True), name="static")

Use make dev to enable hot-reloading.

Front-end Side (TypeScript/Svelte)

cd web/ and check src/App.svelte.

Use make dev to enable hot-reloading.

About

License:MIT License


Languages

Language:JavaScript 29.4%Language:Svelte 24.6%Language:CSS 10.8%Language:Python 10.4%Language:Dockerfile 7.7%Language:Makefile 5.7%Language:SCSS 4.9%Language:HTML 4.8%Language:TypeScript 1.7%