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.

ezoic increase your site revenue

About

License:MIT License


Languages

Language:JavaScript 30.3%Language:Svelte 23.5%Language:CSS 11.1%Language:Python 9.8%Language:Dockerfile 8.0%Language:Makefile 5.6%Language:SCSS 5.0%Language:HTML 4.9%Language:TypeScript 1.8%