I'm trying to find the best design for an API. I have user
and institution
objects. Each user
can have only one institution
, which is represented on the users
table by an institution_id
column.
How should I model an endpoint that would change which institution
a user
is signed up for?
Some of my ideas:
PUT /user/institution
passing in the new institution_id in the body.
PATCH /user
updating the institution_id
column in users
Any suggestions?
I believe that PATCH /user updating the institution_id column in users
is better, because you are updating an attribute in the user model and you can consider it as any other attribute belong to the user like email, address .. etc, since institution_id is a column in user table.
Also using PUT will lead you to provide the whole model when you updating the user and this consuming your network traffic.
BTW, when using PATCH you only provide the attributes that's you want to update, and using PUT you provide the whole user model.
The return data from the 2 verbs (PUT AND PATCH)should be the whole model not only the updated attributes.