composite key resource REST service

前端 未结 2 1447
[愿得一人]
[愿得一人] 2021-02-05 04:28

I\'ve come across a problem at work where I can\'t find information on the usual standard or practice for performing CRUD operations in a RESTful web service against a resource

2条回答
  •  萌比男神i
    2021-02-05 04:56

    I suggest:

    • POST /api/PartsProductsAssoc: Create link between part and product. Include part and product ids in POST data.
    • GET, PUT, DELETE /api/PartsProductsAssoc/: read/update/delete link with (not part or product id, yes, this means creating a new column in your PartsProductsAssoc table).
    • GET /api/PartsProductsAssoc/Parts//Products: get list of products associated with the given part.
    • GET /api/PartsProductsAssoc/Products//Parts: get list of parts associated with the given product.

    Reasons to take this approach:

    • Single, fully-qualified URI for each link.
    • Modifying a link modifies a single REST resource.

    For more info, see https://www.youtube.com/watch?v=hdSrT4yjS1g at 56:30.

提交回复
热议问题