In this recipe, we will be looking at a .NET Standard 2.0 library that calls a REST API. RESTful APIs are services that allow you to access its functionality through HTTP. We will be using the System.Net.Http
namespace inside the library to send a message to an API and get back the results.
Make sure you have the latest version of Visual Studio 2017. Also make sure you have a basic understanding of accessing a web service, what a GET
method is, what a POST
method is, and so on. We will be using a test API service provided by JSONPlaceHolder
. It's a simple REST API test bed for developers.
- Open Visual Studio 2017.
- Click
File
|New
|Project
to create a project. - In the
New Project
dialog box, expand theOther Project Types
node in the left pane and selectVisual Studio Solutions
. In the right pane, selectBlank Solution
.
- In the
Name:
textbox, typeChapter7.RestAPI
and in theLocation:
textbox select a path from the drop-down box...