RESTful API routes design: nested vs. non-nested

前端 未结 3 938
星月不相逢
星月不相逢 2021-02-05 07:26

My question is about the advantages of nesting resources when building URLs for API purposes. Consider the following two alternatives for accessing an employee resource:

3条回答
  •  灰色年华
    2021-02-05 07:44

    I'd vote for 2'nd solution, based on model and security.

    The department is in the path and does not have to be in the payload, neither for read- or write.

    IF depatment of employee is to be changed, the depID could be included in the payload or through separate endpoint (with separate grant) /employees/{ID}.

提交回复
热议问题