简体   繁体   English

在接口中测试 FastAPI 端点

[英]Testing FastAPI endpoints in the interface

I got access to a private GitLab project that contains the following branches: main , develop and new_branch .我可以访问包含以下分支的私有 GitLab 项目: maindevelopnew_branch The machine learning project is pretty complex and contains various transformers for NLP, and many steps that generate some output from an input text.机器学习项目非常复杂,包含 NLP 的各种转换器,以及从输入文本生成一些 output 的许多步骤。 FastAPI has also been used.也使用了 FastAPI。 I am using Windows.我正在使用 Windows。

I followed the instructions and ran pipenv run start :我按照说明运行pipenv run start

←[32mINFO←[0m:     Started server process [←[36m12988←[0m]
←[32mINFO←[0m:     Waiting for application startup.
←[32mINFO←[0m:     Application startup complete.
←[32mINFO←[0m:     Uvicorn running on ←[1mhttp://127.0.0.1:8000←[0m (Press CTRL+C to quit)

I go to http://127.0.0.1:8000 and get (though the instructions say to go to http://localhost:8000/): I go to http://127.0.0.1:8000 and get (though the instructions say to go to http://localhost:8000/):

{"name":"my app API","version":"0.0.1","currentTime":"01/07/2022, 04:41:36"}

And in the terminal:在终端:

←[32mINFO←[0m:     127.0.0.1:65248 - "←[1mGET / HTTP/1.1←[0m" ←[32m200 OK←[0m

But how do I actually play around with the app?但是我如何实际使用该应用程序? I saw a simple example on the internet where I navigate to the endpoint in the browser, but in my case the project is much more complicated and the tree of the folder is huge.我在互联网上看到了一个简单的示例,我在浏览器中导航到端点,但在我的情况下,项目要复杂得多,并且文件夹的树很大。 Anything that I type after the address in browser, it gives me {"detail":"Not Found"} .我在浏览器中的地址之后输入的任何内容都会给我{"detail":"Not Found"}

Since FastAPI is simply a framework for creating APIs, there is no real user interface available (aside from the documentation it generates).由于 FastAPI 只是一个用于创建 API 的框架,因此没有可用的真实用户界面(除了它生成的文档)。 It's not a web app - just a collection of endpoint definitions.它不是 web 应用程序 - 只是端点定义的集合。

From the FastAPI documentation:来自 FastAPI 文档:

Interactive API docs 交互式 API 文档

Alternative API docs 替代 API 文档

If you want to know what endpoints are available in the application, try going to http://127.0.0.1:8080/docs or http://127.0.0.1:8080/redoc .如果您想知道应用程序中有哪些端点可用,请尝试转到http://127.0.0.1:8080/docshttp://127.0.0.1:8080/redoc

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

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