Skip to content

Instantly share code, notes, and snippets.

@lukepighetti
Created March 21, 2023 15:55
Show Gist options
  • Save lukepighetti/e5a8ac87228f3c3d74ef6d00605b63ee to your computer and use it in GitHub Desktop.
Save lukepighetti/e5a8ac87228f3c3d74ef6d00605b63ee to your computer and use it in GitHub Desktop.
A very basic mock python server
# flask --app server run
from dataclasses import dataclass, asdict
from typing import Generic, List, TypeVar
from flask import Flask
app = Flask(__name__)
T = TypeVar("T")
@dataclass
class Workout:
"""A workout"""
id: str
title: str
@dataclass
class ListResponse(Generic[T]):
"""A typical list response"""
data: List[T]
request_id: int
requests = 0
@app.route("/workouts")
def workouts():
global requests
requests += 1
res = ListResponse(
data=[
Workout(id="1", title="Fast Track To Fat Loss"),
Workout(id="2", title="Beach Shredder 9000"),
Workout(id="3", title="Tubular Triceps"),
],
request_id=requests,
)
return asdict(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment