REST API - include related object details or just ID's

前端 未结 2 430
半阙折子戏
半阙折子戏 2021-02-05 15:29

What is the better design practice?

If I have object A and it contains some related objects for example I have a car object and it\'s various types.

Should I on

2条回答
  •  礼貌的吻别
    2021-02-05 16:00

    I prefer the parameterless version of option 1, but I would favor something where the location of the type resource is returned, so that the client may choose whether or not to retrieve those resources.

    Otherwise, we are not navigating the documents. Rather, we would be relying upon some out-of-band data, such as knowing the path to the type in advance.

    {
        "id": 1,
        "name": "Some Car",
        "types": [
            {
                "location": "api.example.org/type/1"
            },
            {
                "location": "api.example.org/type/2"
            }
        ]
    }
    

提交回复
热议问题