c# - How do I create a truly multi-purpose endpoint using WebAPI 2 with optional parameters? -


thanks looking.

i attempting make following code work:

[routeprefix("api/user")] public class usercontroller : apicontroller { [allowanonymous]     [route("{email}")]     public ihttpactionresult get(string email = null)     {                 if (!string.isnullorempty(email))         {             return json(someuserprofileobject);         }          return json(somelistofuserprofiles);     } } 

whenever try , access /api/user/some@email.com, 405.

solved!

please see solution in answer below.

i finish composing question when stumbled on answer. basically, special characters don't work in url request paths. used query string instead , revised code this:

 [routeprefix("api/user")]     public class usercontroller : apicontroller     {     [allowanonymous]         [route("")]         public ihttpactionresult get(string email = null)         {                     if (!string.isnullorempty(email))             {                 return json(someuserprofileobject);             }              return json(somelistofuserprofiles);         }     } 

now works fine , can use endpoint both lists of users individual user if querystring provided.

cheers!


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -