-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (31 loc) · 1016 Bytes
/
main.py
File metadata and controls
40 lines (31 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from fastapi import FastAPI
import pyjokes
from pydantic import BaseModel
app = FastAPI()
@app.get("/")
def joke():
return pyjokes.get_joke()
@app.get("/{friend}")
def friend_joke(friend: str):
return friend + " tells his joke: " + pyjokes.get_joke()
@app.get("/multi/{friend}")
def multy_friends_joke(friend: str, jokes_number: int):
result = ""
for i in range(jokes_number):
result += friend + f" tells his joke #{i + 1}: " + pyjokes.get_joke() + " "
return result
class Joke(BaseModel):
friend: str
joke: str
class JokeInput(BaseModel):
friend: str
# @app.post("/")
# def create_joke(joke_input: JokeInput):
# return joke_input.friend + " tells his joke: " + pyjokes.get_joke()
@app.post("/")
def create_joke(joke_input: JokeInput):
return Joke(friend=joke_input.friend, joke=pyjokes.get_joke())
@app.post("/", response_mofel=Joke)
def create_joke(joke_input: JokeInput):
"""kkkkkk"""
return Joke(friend=joke_input.friend, joke=pyjokes.get_joke())