Web API best practices for deep feature routes

When developing a RESTful API with ASP.NET web API, I can create multiple routes to retrieve the same data. But should I? Is this considered useful or confusing?

For example, if I have an object relationship Parent> Child> Item, I can potentially have three routes returning the same separate element:

  • api / parents /: parent / children /: child / objects /: element
  • api / children /: child / objects /: element
  • api / elements /: element

Is it helpful to provide all three routes, or to limit myself to the simplest way to avoid confusion? Is there a best practice in this regard?

+4
source share
2

, URI/ - , . , ? , URI, , , , parentId.

URI api/children , , , api/parents/:parentId/children, : parentId . , api/children, , ' .

, , . URI .

+2

(: ),

//:

/.

:

api/parents
api/parents/:parentid
api/parents/:parentid/children
api/children
api/children/:childid
api/children/:childid/items
api/items
api/items/:itemid
0

Source: https://habr.com/ru/post/1608695/


All Articles