Figer's Technology Consulting | .NET - Calling Web API functions directly

.NET - Calling Web API functions directly

To get around the default .NET Web API GET calls (http://localhost:10305/api/ISS/?strUser=myusername&strPass=mypassword) where you only specify parameters and not the function name, add this code snippet to  your Global.asax.vb file: 

Public Shared Sub RegisterRoutes(routes As RouteCollection)
routes.MapHttpRoute(name:="DefaultApi", routeTemplate:="api/{controller}/{action}", defaults:=New With {Key .action = "get"})
routes.MapHttpRoute(name:="DefaultApi", routeTemplate:="api/{controller}/{action}", defaults:=New With {Key .action = "post"})
End Sub

Then you can make a call that looks like this: http://localhost:10305/api/ISS/LoginFunction?strUser=myusername&strPass=mypassword This is just an example, don't ever send a username and password like this!
Comments are closed