-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
44 lines (34 loc) · 1.05 KB
/
main.py
File metadata and controls
44 lines (34 loc) · 1.05 KB
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
41
42
43
44
from fastapi import FastAPI, Header, status
from fastapi.exceptions import HTTPException
from typing import Optional, List
from pydantic import BaseModel
app = FastAPI()
@app.get('/')
async def read_root():
return {"message":"Hello Enes!"}
@app.get('/greet')
async def greet_name(name:Optional[str] = "User",
age:int = 0) -> dict:
return {"message":f"Hello {name}","age":age}
class BookCreateModel(BaseModel):
title : str
author : str
@app.post('/create_book')
async def create_book(book_data:BookCreateModel):
return {
"title" : book_data.title,
"author" : book_data.author
}
@app.get('/get_headers',status_code=500)
async def get_headers(
accept:str = Header(None),
content_type: str = Header(None),
user_agent:str =Header(None),
host:str = Header(None)
):
request_headers = {}
request_headers["Accept"] = accept
request_headers["Content-Type"] = content_type
request_headers["User-Agent"] = user_agent
request_headers["Host"] = host
return request_headers