5. Backend
The backend is using Fastapi, and the python version is 3.9+.
- Design API
Send json object to frontend
1@app.get("/hello/{name}") 2async def say_hello(name: str): 3 return {"message": f"Hello {name}"}
In frontend we can use fetch to make a request to backend
1 async fetch() { 2 const helloworld = await fetch( 3 'http://127.0.0.1:8000/hello/model' 4 ).then(res => res.json()) 5 console.log(helloworld); 6},
Send mesh file to frontend
1@app.get("/api/model") 2async def get_display_model(): 3 model_path = "./data/mask.obj" 4 file_res = FileResponse(model_path, media_type="application/octet-stream", filename="mask.obj") 5 return file_res
Receive mesh in frontend via blob
1async fetch() { 2 const model = await fetch( 3 'http://127.0.0.1:8000/api/model' 4 ).then(res => res.blob()) 5 console.log(model); 6},