Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export default defineConfig({
text: 'Styling',
collapsed: true,
items: [
{ text: 'FAST-Graphics', link: '/stacks/frontend/styling/fastgraphics' },
{ text: 'MaterialUI', link: '/stacks/frontend/styling/materialui' },
{ text: 'TailwindCSS', link: '/stacks/frontend/styling/tailwindcss' },
]
Expand Down
Binary file added docs/public/merge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/repository.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/taskid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/versioning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 84 additions & 1 deletion docs/stacks/backend/python/fastapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FastAPI is a modern, fast (high-performance), web framework for building APIs wi

It provides:
- Speed: It is one of the fastest Python frameworks available.
. Auto-Documentation: It automatically generates interactive API documentation (Swagger UI) at /docs. You can test your API directly from the browser without any extra tools.
- Auto-Documentation: It automatically generates interactive API documentation (Swagger UI) at `/docs`. You can test your API directly from the browser without any extra tools.
- Fewer Bugs: It uses Python type hints to catch errors early. If you expect an int and get a string, FastAPI automatically sends back a helpful error message to the client.
- Standards-Based: It is built on open standards like JSON Schema and OAuth2.

Expand Down Expand Up @@ -54,3 +54,86 @@ async def search(query: str, limit: int = 10):
return {"results": f"Searching for {query}", "limit": limit}
```

Run the server using typing `uvicorn <path_to_fastapi_file>:app --reload` in the terminal, in the project root folder.

::: info
The path may be a simple `main`, or something like `backend.api` (no slashes, subfolder separation is with dots), or whatever you want.
:::


### Pydantic Integration

```python
from pydantic import BaseModel

class Item(BaseModel):
name: str
price: float

@app.post("/items/")
async def create_item(item: Item):
return item
```

### CORS

Critical for any frontend-backend setup (for example, Next.js calling the API). Without it, browsers will block requests:

```python
from fastapi.middleware.cors import CORSMiddleware

app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:3000"], # frontend URL
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
```

### Response Models

Very practical: prevents accidentally exposing sensible or unwanted fields in responses:

```python
class UserOut(BaseModel):
id: int
username: str

@app.get("/users/{id}", response_model=UserOut)
async def get_user(id: int): ...
```

### Error Handling

```python
from fastapi import HTTPException

@app.get("/users/{user_id}")
async def get_user(user_id: int):
if user_id not in db:
raise HTTPException(status_code=404, detail="User not found")
```


### Dependency Injection

FastAPI's `Depends` system is a standout feature used for auth, DB sessions, etc. Even a one-liner pointing to the concept is useful:

```python
from fastapi import Depends

def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()

@app.get("/items/")
def read_items(db = Depends(get_db)): ...
```

---

See additional examples on the official docs: https://fastapi.tiangolo.com/
52 changes: 52 additions & 0 deletions docs/stacks/backend/python/pydantic.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,56 @@ except ValidationError as e:
print(e.json()) # Returns a detailed explanation of why it failed
```

The current example is 'flat'. In practice, models nest inside each other (for example, a Project has a list of Users). This is the most direct bridge to how you'd use Pydantic with FastAPI request/response bodies:

```python
class Address(BaseModel):
city: str
country: str

class Employee(BaseModel):
name: str
address: Address # nested model
```


### Model Validator

A very common real-world need is validating relationships between fields (for example, `end_date` must be after `start_date`). This is one of the most asked-about Pydantic features:

```python
from pydantic import BaseModel, model_validator

class DateRange(BaseModel):
start: int
end: int

@model_validator(mode="after")
def check_range(self) -> "DateRange":
if self.end <= self.start:
raise ValueError("end must be greater than start")
return self
```


### Pydantic Settings

This is a separate but closely related package that can become really handy. It reads `.env` files and environment variables into a validated Pydantic model, central to any FastAPI project:

```python
from pydantic_settings import BaseSettings

class Settings(BaseSettings):
database_url: str
api_key: str
debug: bool = False

class Config:
env_file = ".env"

settings = Settings()
```

---

See more suitable examples on the official docs: https://pydantic.dev/docs/validation/latest/examples/files/
9 changes: 9 additions & 0 deletions docs/stacks/frontend/styling/fastgraphics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
outline: deep
---

# <img src="/fast_logo_orange.png" style="display: inline-block; vertical-align: middle; height: 48px; margin-right: 8px"> FAST-Graphics

`@fast-computing/fast-graphics` is the official internal UI & graphics library for company web applications and websites. Built on TypeScript, it provides fully typed, accessible, and performant web components, canvas utilities, and layout primitives.

Full documentation is at https://github.com/FAST-Computing/fast-graphics
Loading