茄子:使用api-first方法创建restapi。

aubergine的Python项目详细描述


License: MIT

aubergine是一个库,可以帮助您轻松地使用 API优先方法。

aubergine中创建api非常简单,只需要以下步骤:

  1. 创建openapi 3规范文件,将operationId设置为您选择的可调用文件。
openapi:"3.0.0"servers:-url:/v1/restinfo:version:1.0.0title:Hello Worlddescription:My first api.paths:/hello:get:operationId:hello_world.helloparameters:-who:whoin:querydescription:who to greatrequired:trueschema:type:stringresponses:'200':description:Greeting dedicated to given name.content:application/json:schema:$ref:'#/components/schemas/Greeting'components:schemas:Greeting:required:-messageproperties:message:type:string
  1. 实现您在规范中声明的操作。将包含以下内容的hello_world模块放在可导入目录中。
defhello(who):"""Handles v1/rest/hello"""return{'message':'Hello {}!'.format(who)}
  1. 告诉茄子为你创建一个应用程序。创建包含以下内容的hello_app.py
fromaubergineimportAubergineapp=Aubergine.from_file('hello_world.yml')api=app.build_api()
  1. 你的应用程序已准备就绪。您可以在任何wsgi服务器上运行它,就像这样:
gunicorn hello_app:api

导航到http://localhost:8000/v1/rest/hello?who=World

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java JTable无法向新创建的列添加值   java如何调整JEditorPane中编辑区域的大小?   Java通过反射确定未知数组中的数组大小   java Intellij Idea有时无法按其预期的方式构建应用程序   java Swing GUI带有IntelliJ错误“contentPane不能设置为null”从终端编译时   如何将这些通用方法调用从C#转换为Java   在null上找不到java属性或字段“index”   从Java HashMap获取整数值时是否需要调用intValue()方法?   java Android谷歌地图获取相机中的图像块   unix无法捕获JAVA中“who m”命令的输出   java,同时将邮件发送到“收件人”标题“我”中的多个收件人   在java中向链表添加未知数量的节点   无法为Heroku上的discord bot设置java端口   java使用Apache HttpClient进行选项请求   与元素类型“ApplicationName”关联的属性“Application Version”需要java Open quote   Android Studio Java中的两个变量求和