1

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?

4
  • 1
    One thing for sure, once you've made your decision you should stick to it.
    – Marc-Andre
    Commented Feb 12, 2014 at 19:46
  • The decision has been made for me, I'm just wondering if it's really the best one. Commented 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
    Commented Feb 12, 2014 at 20:21
  • 2
    Rolling On the Laminated Floor Laughing? Commented Feb 12, 2014 at 21:26

1 Answer 1

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.