Service API Specification [chapter] deterministic
## Endpoints - `GET /users` - List all users - `GET /users/{id}` - Get user by ID - `POST /users` - Create a new user ## Data Model User: id: int name: string email: string ``` #### Step 2:
Endpoints
GET /users- List all usersGET /users/{id}- Get user by IDPOST /users- Create a new user
Data Model
User: id: int name: string email: string
`
#### Step 2: Parse the Document
We'll use a simple parser to extract the endpoints and data model:
```python import re from dataclasses import dataclass from typing import List
@dataclass class Endpoint: method: str path: str description: str
@dataclass class Field: name: str type: str
@dataclass class Model: name: str fields: List[Field]
def parse_api_spec(markdown: str):
endpoints = []
models = []
# Simple regex-based parsing
for line in markdown.splitlines():
m = re.match(r"^- (\w+) (.+) - (.+)$", line)
if m:
endpoints.append(Endpoint(m.group(1), m.group(2), m.group(3)))
m = re.match(r"^(\w+):$", line)
if m:
model_name = m.group(1)
Source Code and Repositories
This chapter draws from the following open-source projects by DanielKliewer:
- **sovereign**: https://github.com/kliewerdaniel/sovereign
- **dynamic_persona_moe_rag**: https://github.com/kliewerdaniel/dynamic_persona_moe_rag
- **SynthInt**: https://github.com/kliewerdaniel/SynthInt
- **workflow**: https://github.com/kliewerdaniel/workflow
- **sovereignSpec**: https://github.com/kliewerdaniel/sovereignSpec
- **RedToBlog02**: https://github.com/kliewerdaniel/RedToBlog02
For more projects, visit https://github.com/kliewerdaniel
---
<>assistant> <>assistant>