I read in a post that it is ideal to put that it is a good standard to include a Location header that points to the URL of the new resource (newly created via POST). My problem is I do not know how to include it.
I am using a class-based views using the APIView and my code in the view is:
class ListArtists(APIView):
serializer_class = ArtistSerializer
def get(self, request, format=None):
_array = Artist.objects.filter()
serializer = self.serializer_class(_array, many=True)
if serializer.data:
_status = status.HTTP_200_OK
else:
_status = status.HTTP_204_NO_CONTENT
return Response(standardResponse(data=serializer.data), status=_status)
def post(self, request, format=None):
serializer = self.serializer_class(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(standardResponse(data=serializer.data), status=status.HTTP_201_CREATED)
else:
return Response(standardResponse(errors=serializer.errors))
artist = ListArtists.as_view()
urls.py
from django.conf.urls import url, include
from store import views
urlpatterns = [
url(r'^artists/', views.artist, name='artists-list'),
]
P.S.
Every time I throw a request using my Advanced REST Client this is the response that I receive:
Date: Sat, 23 Jul 2016 10:54:23 GMT
Server: WSGIServer/0.1 Python/2.7.10
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN
Content-Type: application/json
Allow: GET, POST, HEAD, OPTIONS