RESTful Many-to-Many possible?

前端 未结 3 1995
天命终不由人
天命终不由人 2020-12-28 09:19

How to I represent a complex resource for a REST post?

Hello, Currently I have an application which when the user hits \"save\" it iterates over all of the form el

3条回答
  •  长情又很酷
    2020-12-28 09:34

    I'm dealing with the exact same thing. I opted to not use id's anywhere, but use urls everywhere an id would normally be expected.

    So in your case, the kitchenfeatures could simply be an array with urls to:

    /feature/1
    /feature/23
    

    And the themes to

    /propertyTheme/12
    /propertyTheme/32
    etc..
    

    In the case of many-to-many relationships, we update all the relations as a whole. Usually we simply dump the existing data, and insert the new relationships.

    For one to many relationships we sometimes extend the urls a bit where this makes sense. If you were to have comments functionality on a 'property', this could look like

    /property/1/comment/5
    

    But this really depends on the situation for us, for other cases we put it in the top-level namespace.

    Is this helpful to you?

提交回复
热议问题