Testing the Web API
Now that we have a Web API created, we will look at options to validate our Web API functionality. Testing is a crucial stage in the creation of Web API development and publishing. There are a couple of different ways of doing this. We can just test it by requesting the URL in a browser or write code and leverage the System.Net.HttpClient
type. This section discusses both of these approaches.
Testing in a browser
Testing a Web API is as simple as developing it, since each action in a Web API controller represents a resource, we can just type the URL of the resource and fetch the results.
- Press F5 in Visual Studio to launch the Web API in a browser.
- Visit the following URL:
http://localhost:<PORT>/api/package/1
Note
Note that the port will be allocated by IIS Express and will be different for each installation.
- This yields a result similar to the following in the browser:
{ "Id": 1, "AccountNumber": "43a2a3eb-e0b8-4840-9e5e-192214a79d58...