From 4cf10d28d7912bfff6a196d5f7b21438e128ed6a Mon Sep 17 00:00:00 2001 From: Tim Schwenke Date: Tue, 16 Aug 2022 18:04:57 +0200 Subject: [PATCH] squash! Add endpoint --- src/testbench_tuna/main.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/testbench_tuna/main.py b/src/testbench_tuna/main.py index aa4e4d6..ffdf4f8 100644 --- a/src/testbench_tuna/main.py +++ b/src/testbench_tuna/main.py @@ -1,6 +1,6 @@ from typing import Union -from fastapi import FastAPI +from fastapi import FastAPI, HTTPException from . import utils @@ -15,3 +15,13 @@ async def get_root(): @app.get("/pizza-size") async def get_pizza_size(diameter: Union[int, float]): return {"area": utils.pizza_size(diameter)} + + +@app.get("/users/{username}/email") +async def get_users_username_email(username: str): + if username == "foo": + return {"username": username, "email": "foo@example.com"} + elif username == "bar": + return {"username": username, "email": "bar@example.com"} + else: + raise HTTPException(status_code=404, detail="User not found")