I'm using django piston to implement my RESTful API. I already implemented an api which is
/api/[uuid of user]
will give all the information related to uuid of user.
However, I also want to implement another api
/api/user/username
where the output should exactly the same as the previous one.
I don't want to maintain two api with different input but has the same input. Therefore, what I want to do is redirect the piston api call. After searching around on the internet, it seems that piston can not do it (correct me if I'm wrong), so I come out of a workaround. For the second api, I can use django's view function to realize, and if the username does exist, then return the handler. If not exist, then return the error message in view function. My code is the following.
def username_url_map(request, username):
try
user = UserProfile.objects.get(user = username)
except UserProfile.DoesNotExist:
return HttpResponse(simplejson.dumps({'error':'This user does not exist.' }), mimetype='application/json')
except UserProfile.MultipleObjectsReturned:
return HttpResponse(simplejson.dumps({'error':'This user does not exist.'}), mimetype='application/json')
uuid = user.uuid
results=GenericHandler.read(request, uuid)
json = simplejson.dumps(results)
return HttpResponse(json, mimetype='application/json')
But I get the following error message:
TypeError
Exception Value: unbound method wrapper() must be called with GenericHandler instance as first argument (got WSGIRequest instance instead)