I'm coding a REST API with Django REST framework. The API will be the backend of a social mobile app. After following the tutorial, I can serialise all my models and I am able to create new resources and update them.
I'm using AuthToken for authentication.
My question is:
Once I have the /users
resource, I want the app user to be able to register. So, is it better to have a separate resource like /register
or allow anonymous users to POST to /users
a new resource?
Also, some guidance about permissions would be great.
I typically treat the User view just like any other API endpoint that required authorization, except I just override the view class's permission set with my own for POST (aka create). I typically use this pattern:
For good measure, here is the serializer I typically use with it:
djangorestframework 3.3.x / Django 1.8.x
All of the answers so far create the user, then update the user's password. This results in an two DB writes. To avoid an extra unnecessary DB write, set the user's password before saving it: