I am trying to implement a simple get / post api through the Django REST framework
views.py
class cuser(APIView): def post(self, request): stream = BytesIO(request.DATA) json = JSONParser().parse(stream) return Response()
urls.py
from django.conf.urls import patterns, url from app import views urlpatterns = patterns('', url(r'^challenges/',views.getall.as_view() ), url(r'^cuser/' , views.cuser.as_view() ), )
I'm trying to POST add json to /api/cuser/ (api is the namespace in my urls.py project), JSON
{ "username" : "abhishek", "email" : " john@doe.com ", "password" : "secretpass" }
I tried from both pages the view API and httpie (a tool created by python that looks like curl)
httpie command
http --json POST http://localhost:58601/api/cuser/ username=abhishek email=john@doe.com password=secretpass
but I get a JSON parsing error:
JSON parse error - Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
Whole Debug message using --verbose --debug
POST /api/cuser/ HTTP/1.1 Content-Length: 75 Accept-Encoding: gzip, deflate Host: localhost:55392 Accept: application/json User-Agent: HTTPie/0.8.0 Connection: keep-alive Content-Type: application/json; charset=utf-8 {"username": "abhishek", "email": " john@doe.com ", "password": "aaezaakmi1"} HTTP/1.0 400 BAD REQUEST Date: Sat, 24 Jan 2015 09:40:03 GMT Server: WSGIServer/0.1 Python/2.7.9 Vary: Accept, Cookie Content-Type: application/json Allow: POST, OPTIONS {"detail":"JSON parse error - Expecting property name enclosed in double quotes: line 1 column 2 (char 1)"}