Exposing locally running Web API to external world using ngrok

Web API Local URL

http://localhost:61204/

ngrok to make this URL work for external users

ngrok http [port] -host-header="localhost:[port]"

Advertisements

ASP Net Web Api : define data format in url

Content negotiation is one of the strong pointy in web api and thats pretty cool. 

Now i can just change the type of response via url only. 

To achieve this just add the following  one line of code 

GlobalConfiguration.Configuration.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping(“format”, “json”, “application/json”));

 

Now i can get json via url : 

http://localhost:18308/api/values?format=json

for xml 

http://localhost:18308/api/values

OR 

http://localhost:18308/api/values?format=xml