简体   繁体   English

DRF,如何将api端点的接口参数传达给其他程序员?

[英]DRF, how to communicate interface parameters for api endpoints to other programmers?

For instance I have the following endpoint, and want to let our client programmers know that he needs to send email/password1/password2 and he would get UserSerializer format data. 例如,我有以下端点,并且想让我们的客户程序员知道他需要发送email/password1/password2并且他将获得UserSerializer格式数据。

How can I effectively let others know the api specification without forcing him to drill down the code? 如何有效地让其他人知道api规范,而不必强迫他深入研究代码?

 @list_route(methods=['post'], permission_classes=[permissions.AllowAny])
 def register(self, request, *args, **kwargs):
     from django.contrib.auth import get_user_model
     from django.contrib.auth import login as login_base

     User = get_user_model()

     email = request.data.get('email')
     password1 = request.data.get('password1')
     password2 = request.data.get('password2')

     ... 


     user.send_activation_email(request=request)
     # login_base(request, user)
     serializer = self.get_serializer(user)

     return Response(serializer.data)

You can use a library for automated API schema generation. 您可以使用库来自动生成API模式。

drf-yasg is one of the most popular libraries for this purpose in DRF, here is an example photo of what you can achieve with it: drf-yasg是DRF中为此目的最受欢迎的库之一, drf-yasg是使用该库可以实现的示例照片: drf-yasg API文档示例

Everything related to it is very well described in the GitHub itself, so you may give it a try. 与它相关的所有内容在GitHub本身都有很好的描述,因此您可以尝试一下。

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

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