简体   繁体   English

如何使用Django Rest框架创建功能性api?

[英]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.

相关问题 如何使用Django Rest Framework创建登录API? - How do I create a login API using Django Rest Framework? 如何使用 Django Rest Framework 创建“添加到收藏夹”功能 - How to create "add to favorites" functional using Django Rest Framework 如何在 Django REST framework 的 Browsable API 中编辑收藏夹图标? - How do i edit the favicon in the Browsable API in Django REST framework? 如何使用 Django Rest Framework 创建多个模型实例? - How do I create multiple model instances with Django Rest Framework? 如何使用django-rest-framework创建Login视图 - How do I create a Login view with django-rest-framework 如何使用命名空间调用Django Rest Framework URL? - How do I call a Django Rest Framework URL using namespacing? 如何使用 django rest 框架创建 Django API? - How to create a Django API using django rest framework which shows response from some external source? 如何基于Django和API REST Framework创建API? - How can I create API with Django and API REST Framework but based on existing models? 如何使用 python Django 和 django-rest-framework 解构 API? - How do I destructure an API with python Django and django-rest-framework? 如何在不使用 Django Rest Framework 中的序列化程序的情况下开发 rest api? - How to develop a rest api without using serializer in Django Rest Framework?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM