简体   繁体   English

如何从 NodeJS 调用 FastAPI 路由?

[英]How to call a FastAPI route from NodeJS?

this is my FasiAPI route:这是我的 FasiAPI 路线:

@app.post("/files/")
async def create_file(file: UploadFile = Form(...)):
    #some ml code
    return {'detected_face': base64_return, 'feature_vector': str(embedded)}

My webapp backend is running on NodeJs + ExpressJS.我的 webapp 后端在 NodeJs + ExpressJS 上运行。 I have the file store in './uploads/filename.jpeg'我在“./uploads/filename.jpeg”中有文件存储

FastAPI is running on: localhost:8000 FastAPI 运行在: localhost:8000

Web backend server running on: localhost:3000 Web 后端服务器运行在: localhost:3000

Thanks in advance!提前致谢!

You can send request directly through url: localhost:8000/ by using request module.您可以使用请求模块直接通过 url: localhost:8000/ 发送请求。

request('http://localhost:8000/files/<parameter>', function (error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log(body)
    }
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM