John Livermore
John Livermore

Reputation: 31333

REST route for alternative Get query type of calls

I am using .NET Web API and need a strategy for route creation of queries. For example, say from the page the code is at a decision point and needs direction from business logic on the server about how to proceed.

Just for review this route will return a standard user...

http://mysite/api/user/5

However, if I want to know if the user has some characteristic determined by business logic which I would make a UI decision on, what would a good REST call be for something like this?

Maybe...

http://mysite/api/user/5?canbake=true

Or is this better...

http://mysite/api/user/5/canbake

And if the latter, then what does the route definition look like to make that happen?

Upvotes: 1

Views: 256

Answers (1)

Phillip
Phillip

Reputation: 94

I believe the general consensus is that the latter is better.
That said, the route definition would look something like:

public static void RegisterApiRoutes(HttpConfiguration config)
{
    config.Routes.MapHttpRoute(
        name:"UserApi",
        routeTemplate: "api/{controller}/{id}/{bake}",
        defaults: new 
            {
                bake = RouteParameter.Optional
            });
}

Upvotes: 2

Related Questions