29

Azure REST APIs in VS Code with Thunder Client

 3 years ago
source link: https://blog.jongallant.com/2021/04/azure-rest-apis-vscode-thunder-client/?utm_campaign=Feed%3A+jongallant+%28Jon+Gallant%29
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Azure REST APIs in VS Code with Thunder Client

azure-rest-apis-vscode-thunder-client.png

Thunder Client is a new REST client VS Code extension. It’s like Postman, but integrated into VS Code. I’d consider it an early preview and far from the feature richness and maturity of Postman, but cool nonetheless.

Here’s how to use it to call the Azure REST APIs.

Install Thunder Client

You can install it here: Thunder Client Install

Or search for it from the VS Code extensions pane:

1.png

Create a Service Principal

We’re going to use OAuth 2.0 to call the Azure REST APIs and we’ll use a Service Principal to do so.

  1. Install the Azure CLI
  2. Open a terminal and run this command to create a Service Principal.
az login
az ad sp create-for-rbac --role Contributor

You’ll need the outputted info in a sec, so save it.

Create Thunder Client Azure Env

  1. Click on the Thunder Client VS Code icon, select Env, and then select New Environment

2.png

  1. Name it “Azure”
  2. Add the following values:

tenantId: Set to tenantId outputted from above command.
clientId: Set to appId outputted from above command.
clientSecret: Set to password outputted from above command.
subscriptionId: Set to your current subscriptionId, you can get with az account show
scope: https://management.azure.com/.default

3.png

  1. Click Save

Create a New Request

  1. In Thunder Client, click the New Request button

4.png

  1. Set Url to https://management.azure.com/subscriptions/{{subscriptionId}}/resourcegroups?api-version=2020-09-01
  2. Under Auth -> OAuth 2.0, set:

Grant Type: Client Credentials
Token Url: https://login.microsoftonline.com/{{tenantId}}/oauth2/v2.0/token
Client ID: {{clientId}}
Client Secret: {{clientSecret}}
Scope: {{scope}}

5.png

  1. Click the “Generate Token” button

Execute the Request

  1. Click the “Send” button

6.png

  1. View the results in the Response pane:

7.png

Save Request to Collection

To save the the request to a collection, click on “Activity”, then the “…”, then “Save to Collection”.

8.png

Give the collection a name, like “Azure REST”.

Then click on “Collections” to see your collections.

9.png

Conclusion

This was a quick post to get you setup with Azure REST APIs in VS Code with Thunder Client. You can explore all of the other Azure REST APIs here: https://docs.microsoft.com/en-us/rest/api/azure/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK