Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I have a question about http://www.django-rest-framework.org/tutorial/2-requests-and...

Is it a good practice to handle all verbs in the function dealing with the particular request as shown in the example?

I think for a real world scenario that would be a mess to read, but for a less experienced developer this could hint that such approach is alright and result in a less readable code base in the future.



If you proceed with the tutorial it is going to show you what I consider is the cleanest way to go for views in django rest framework (ViewSets, coupled with the routers, part 6 of the tutorial).

Basically, you will 1. split verbs to different methods of one class and 2. you can not implement verbs you are not going to allow (you can of course do that also with the functional style you see in the link you posted)


Having maintained a DRF-based API before, +1 to using ViewSets.


The intro tutorial tends to show you the low-level/more-code-but-infinitely-customizable way a thing really works, and then once you understand that, introduce the convenient abstractions on top of it that make common cases simpler/less code. So keep reading :)


For a typical setup, you can just use the built in Routers. It's a much cleaner way to handle all the verbs. You can always override functions if you need it to do something special.

http://www.django-rest-framework.org/api-guide/routers/




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: