You can create a client SDK from APIs registered on API Center using Visual Studio Code. This section will guide you through the integration process.
To use this feature, you need to install the API Center extension in Visual Studio Code. In addition to that, you may be asked to install the Microsoft Kiota extension.
-
Open the API Center extension, navigate down to the API definition, and right-mouse click on the API definition. Then choose the "Generate API Client" option.
-
When the pop-up modal appears, click the "Open" button.
-
When the Kiota extension opens, make sure that everything is selected and click the
▶️ button to generate an API client. -
The prompt asks several questions in the order. Enter the following values:
- Choose a name for the client class 👉
WeatherClient
- Choose a name for the client class namespace 👉
WebApp.ApiClients
- Enter an output path relative to the root of the project 👉
nodejs/webapp/src/ApiClients
- Pick a language 👉
TypeScript - preview
- Choose a name for the client class 👉
-
After the client is generated, you can see the client class in the specified output path.
-
While in the root of the project, run the following command to install the required packages and run the web application.
cd nodejs/webapp && npm install && npm start
-
On
localhost:3000
, you will see the following UI, but when you navigate to the Weather page, you only see an empty table with no weather data. -
Let's make a small modification to the code to make the client SDK work. Open
src/components/WeatherList.js
and uncomment all the commented out code.
Note
This code sets up an anonymous authentication provider and a fetch request adapter to create a weather client. The getWeatherForecast
function uses the client to fetch weather data from the API.