Last active
February 9, 2019 21:54
-
-
Save barseghyanartur/3696cb88b872ce284867165f76e4596b to your computer and use it in GitHub Desktop.
Minimalistic REST API view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf.urls import url | |
from views import sample_api_view | |
urlpatterns = [ | |
url( | |
r'^sample-api-view/$', | |
sample_api_view, | |
name="sample_api_view" | |
), | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from rest_framework.decorators import api_view | |
from rest_framework.response import Response | |
@api_view(http_method_names=['GET', 'POST']) | |
def sample_api_view(request): | |
data = json.dumps(request.data) | |
return Response(data) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from rest_framework.views import APIView | |
from rest_framework.response import Response | |
class SampleApiView(APIView): | |
def get(self, request, format=None): | |
data = json.dumps(request.data) | |
return Response(data) | |
def post(self, request, format=None): | |
data = json.dumps(request.data) | |
return Response(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment