[英]How do I create a functional api using django rest framework?
I am trying to use mailgun's api on a landing page made through unbounce.com, however I discovered that I can't make requests client side. 我试图在通过unbounce.com建立的目标网页上使用mailgun的api,但是我发现我无法在客户端发出请求。 I do have django set up, so, I'd like to use that to make api calls to mailgun instead.
我确实设置了django,因此,我想用它来对mailgun进行api调用。
So, my question is how do I create using django-rest-framework, an API that would make the api calls for me and return the response. 因此,我的问题是如何使用django-rest-framework创建该API,该API将使api代我调用并返回响应。 I have used drf before, but mostly serializing models, and this time I'd like to make a function-based api
我以前使用过drf,但是主要是序列化模型,这次我想制作一个基于函数的api
I expect to make a call to mailgun and pass a parameter called email so that I can use something like domain.com/api/mailgun/email="email@email.com" 我希望打电话给mailgun并传递一个名为email的参数,以便我可以使用domain.com/api/mailgun/email="email@email.com“之类的东西。
You can use APIView for your endpoint and requests library for mailgun api 您可以将APIView用于您的端点并为Mailgun API请求库
class MailView(APIView):
def get(request):
email = request.query_params.get('email', None)
"""
some valdiations ..
"""
response = requests.get('http://mailgun-api/')
return Response(data=response.json())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.