You can do it this way:
[Route("api/DeliveryItems/{ID:int}/{CountToFetch:int}")]
...calling it like so:
http://localhost:28642/api/deliveryitems/N/N
...which has the benefit of the routing attribute documenting exactly which args the methods needs.
Or you can do it this way:
[Route("api/DeliveryItems")]
...calling it like so:
http://localhost:28642/api/deliveryitems?ID=N&CountToFetch=N
...which has the benefit of having a clear "separation of concerns" (or perhaps "separation of context" or "separation of intent"), so that path info is one thing, args are another, and never do the twain meet (in the routing attribute string, at any rate).
Any powerful reasons to opt for one style over the other?
-
1One thing for sure, once you've made your decision you should stick to it.Marc-Andre– Marc-Andre2014年02月12日 19:46:13 +00:00Commented Feb 12, 2014 at 19:46
-
The decision has been made for me, I'm just wondering if it's really the best one.B. Clay Shannon-B. Crow Raven– B. Clay Shannon-B. Crow Raven2014年02月12日 19:46:50 +00:00Commented Feb 12, 2014 at 19:46
-
This question appears to be off-topic because it is about design decisions which would be more appropriate for Software Engineering.rolfl– rolfl2014年02月12日 20:21:27 +00:00Commented Feb 12, 2014 at 20:21
-
2Rolling On the Laminated Floor Laughing?B. Clay Shannon-B. Crow Raven– B. Clay Shannon-B. Crow Raven2014年02月12日 21:26:47 +00:00Commented Feb 12, 2014 at 21:26
1 Answer 1
I don't really know about ASP.NET-MVC, but in RoR the convention is to use a combination that'll look like this:
[Route("api/{ID:int}/DeliveryItems")]
And you'll use it like this:
http://localhost:28642/api/N/deliveryitems?CountToFetch=M
How do you decide which parameters get in the path and which get in the query string? Think OOP! The HTTP request is running a method of an object. The path is for fetching the object and deciding the method while the query string is for specifying the arguments.
Assuming that ID
is the id of a category of items to deliver, that category would be a ItemsCategory
object and the HTTP request will resemble:
API.FetchItemsCategory(N).FetchDeliveryItems(M)
Take a look at REST
-
1" Think OOP!" I think "Oops!" quite a bit when I'm coding, actually.B. Clay Shannon-B. Crow Raven– B. Clay Shannon-B. Crow Raven2014年02月12日 21:39:36 +00:00Commented Feb 12, 2014 at 21:39