I think something like this? urls.py import views urlpatterns = [ url(r'^server_time', views.ServerTimeView.as_view(), name='server_time'), ]
views.py import datetime from rest_framework.views import APIView from rest_framework.response import Response class ServerTimeView(APIView): def get(self, request, format=None): return Response({ 'server_time': datetime.datetime.utcnow() }) def post(self, request, format=None): try: new_time = datetime.datetime.strptime(request.data['server_time'],"%Y-%m-%dT%H:%M:%S") # set the system time to "new_time" return Response({ 'response': new_time }) except: pass curl -i --request POST -H "Content-type: application/json" --data '{"server_time":"2016-06-21T03:31:45"}' http://192.168.1.120:8000/api/server_time I don't think you need serializers. On 06/20/2016 07:25 PM, 'Abraham Varricatt' via Django REST framework wrote: > Hello, > > Is it possible to use Django Rest Framework (DRF) for something other > than models? Here's a trivial example, > > To make an API end point which returns the current server time (in JSON > format, eg: {"current_time": "XYZ"}). It can accept a string to indicate > timezone, and must accept both GET and POST. > > I can figure out how to do the above without DRF using regular Django > urls and views. What I can't figure out is how to use DRF for the same. > > From the docs, it looks best to use routers when making a DRF end-point. > Which means I need a structure like this, > > urls.py <-> router <-> Viewset <-> Serializer > > But as I understand Serilizers ( > http://www.django-rest-framework.org/api-guide/serializers/ ), they can > only be used for complex models or querysets - which is not what I need. > > I feel like I'm mis-understanding something about DRF. Help please? > > Puzzled, > Abraham V. > > -- > You received this message because you are subscribed to the Google > Groups "Django REST framework" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to django-rest-framework+unsubscr...@googlegroups.com > <mailto:django-rest-framework+unsubscr...@googlegroups.com>. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.