A
A
alex995052015-10-21 23:57:38
ASP.NET
alex99505, 2015-10-21 23:57:38

How to properly configure routing in Web.API?

How to make two requests go through:
localhost:42648/api/values/Table_name(1)
localhost:42648/api/values/Table_name(1)/field?sel...
"Server error in application '/'.
Failed find this resource.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2015-10-22
@yarosroman

in WebApiConfig.cs we write:

config.Routes.MapHttpRoute(
            name: "SafetyApi",
            routeTemplate: "api/{controller}/{table}/{field}/{sortby}"
            );

in controller:
public async Task<IEnumerable<Table>> Get(string table, string field, string sortby)
{

}

that's it, now when you call
localhost:42648/api/values/Table_name/Field1/desc
, the Get method will be called with the parameters table=Table_name, field=Field1, sortby=desc.
routing was invented to get rid of all sorts of field?select=...&.....&.....&....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question