-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
24 lines (18 loc) · 794 Bytes
/
main.py
File metadata and controls
24 lines (18 loc) · 794 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
from typing import Annotated
from rust_idl import hello
from typing import Union
from fastapi import FastAPI, Response, Header
app = FastAPI()
@app.get("/hello/{name}")
def greet(name: str, accept: Annotated[str, Header()] = None):
greeting = hello.Hello(name)
if accept == "application/msgpack":
response = Response(content=greeting.to_msgpack())
response.headers["Content-Type"] = "application/msgpack"
else:
response = Response(content=greeting.to_json())
response.headers["Content-Type"] = "application/json"
response.headers["Access-Control-Allow-Origin"] = "*"
response.headers["Access-Control-Allow-Methods"] = "GET, POST, OPTIONS"
response.headers["Access-Control-Allow-Headers"] = "Content-Type, Accept"
return response