Skip to content

Instantly share code, notes, and snippets.

@barseghyanartur
Last active February 9, 2019 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barseghyanartur/3696cb88b872ce284867165f76e4596b to your computer and use it in GitHub Desktop.
Save barseghyanartur/3696cb88b872ce284867165f76e4596b to your computer and use it in GitHub Desktop.
Minimalistic REST API view
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"
),
]
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)
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