Created
March 21, 2023 15:55
-
-
Save lukepighetti/e5a8ac87228f3c3d74ef6d00605b63ee to your computer and use it in GitHub Desktop.
A very basic mock python server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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