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

前端 未结 2 464
半阙折子戏
半阙折子戏 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:18

    This touches one of the core principles of REST called HATEOAS (Hypermedia As The Engine Of Application State).

    Object IDs are useless and meaningless to clients. What do you do with them? Feed them to a search function? Construct a new URI with them appended to the end of it? Phone a 1-800 number and ask what to do with them? Print them out on paper and mail them to a government agency that helps API clients find their next steps?

    Just return the full URI, all the time. The ID given to the client should always be the URI - it's something which uniquely identifies the resource in question and can be used to retrieve, update or remove it.

提交回复
热议问题