Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to bulk update/insert via nested url? #131

Open
simkimsia opened this issue Dec 3, 2018 · 3 comments
Open

How to bulk update/insert via nested url? #131

simkimsia opened this issue Dec 3, 2018 · 3 comments

Comments

@simkimsia
Copy link

Using the nameserver and domain example, I like to send a list of domains to the nested route

/nameservers/{nameserver-pk}/domains

and then I can write code to decide to which domain is supposed to be a brand new record or which domain is supposed to update.

How do I do that using nested-routers?

I am okay to write my own code, I am not sure how to use the right viewset and serializer for this.

@himanshu-singh1995
Copy link

himanshu-singh1995 commented Dec 9, 2018

As you are using drf-nested-router, I assume you want to adhere to the rest architecture.

Using the nameserver and domain example, I like to send a list of domains to the nested route

/nameservers/{nameserver-pk}/domains

Doing so is not recommended by REST architecture. As REST architecture provide CRUD operations(
get on /nameservers/{nameserver-pk}/domains gives list of domains of the nameserver
post on /nameservers/{nameserver-pk}/domains add a domain to nameserver
) but here you tring to add a custom operation. So REST recommends
POST request on /nameservers/{nameserver-pk}/domains/bulk-create (not exactly bulk-create, you can have here whatever you want) for bulk create.

This can be easily achived by adding a list_route with path='bulk-create, methods=[post]' in DomainViewSet

@GregEremeev
Copy link

GregEremeev commented Jun 14, 2019

Doing so is not recommended by REST architecture.
So REST recommends
POST request on /nameservers/{nameserver-pk}/domains/bulk-create

@himanshu-singh1995 Can you provide a link to clarify that comment? Where did you get that?

@alanjds
Copy link
Owner

alanjds commented Jun 14, 2019

Well, this is very debatable @himanshu-singh1995. Some would say that using nested objects is not RESTful just to start.

My position is that a POST with a list on the {}/domains/ is preferred than a POST with a list on {}/domains/bulk-create subpath.

@simkimsia I would answer as if every member of the list had been POSTed alone. On the view, you can differentiate by verifying if the request cames with a dict or a list on the 1st level, for example.

However, is just an opinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants