WebAPI Calls & Results
Integration with other applications is based on Web API calls. The .NET runtime looks for all types that derive from the ApiController type. Application has Application_Start event allowing hook up and route requests to scpecific contollers.
Although WebPAI calls can be made directly in the browser, many browsers fail to display JSON results by default. It’s also helpful to see the HTTP Results code to debug what’s happening under the covers.
For the purposes Fiddler allows monitoring the WebAPI requests rather than fiddle with the browser settings.

Using Fiddler
Fiddler is used to initiate the request based on URL and get response.
1. Hit F5 to launch app and get the root URL. In my case, it’s http://localhost:54565/HTMLClient/
2. With the app still running Launch Fiddler
3. Select the Composer tab, and enter http://localhost:54565/api/Places/3, then hit Enter or the Execute button
fiddler1.png
Since Place with Id=3 request is a Get, it’s routed to the Get method in PlacesController class. Because we passed a parameter, it’s passed to the Get(int id) overload method of this class.
If you double click the Web Session, click on the JSON tab for result formatting, you’ll see “value” returned from our basic WebAPI controller in JSON format.
fiddler2.png
4. Now let's try to get nearest available place within 100000 meters from current place. Let's pretend the current place has Longitude=138 and Latitude=-35. Run new request using composer:
http://localhost:54565/api/Places?Longitude=138&Latitude=-35&MaxDistance=100000
fiddler3.png
Place Controller routes this URL request to overloaded Get method matched with parameters. Then SQLAccess class method named GetNearestPlaces calls stored procedure mmc_GetNearestPlaces. Finally responce is send back to client in JSON format.
fiddler4.png
Full list of controllers could be found here.

Last edited Jul 22, 2013 at 2:08 AM by ban, version 20

Comments

No comments yet.