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?

asked Feb 12, 2014 at 19:34
4
  • 1
    One thing for sure, once you've made your decision you should stick to it. 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. 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

answered Feb 12, 2014 at 21:36
1
  • 1
    " Think OOP!" I think "Oops!" quite a bit when I'm coding, actually. Commented Feb 12, 2014 at 21:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.