Built-in REST Client with .http files - request variables support

Oleksii Kovalchuk 65 Reputation points
2023-03-02T08:03:23.4866667+00:00

Hi guys,

VS 2022 v17.5 supports built-in REST Client tool that works with .http files to test the APIs.

It's pretty awesome feature, but it's not documented. There are similar tools/extensions docs, but as I can see - it's a built-in tool rather than extension.

It has variables support in general, but what about request variables?

Request variables could help developers to organize requests in a flow. The simplest scenario is authentication. But the code below does not work as it does not set "authPasswordRequest" and "@accessToken" variable gets initialized with "{{authPasswordRequest.response.body.$.access_token}}" expression string, rather than having it evaluated properly.


@baseUrl = https://some.url
@contentType = application/json

### Login Request (responds with 'access_token' in JSON response body):
# @name authPasswordRequest
POST {{baseUrl}}/auth/password
Content-Type: {{contentType}}

{
  "userName": "username",
  "password": "password"
}

### Get User Profile Request:
@accessToken = {{authPasswordRequest.response.body.$.access_token}}
# @name userProfileRequest
GET {{baseUrl}}/profile
Authorization: Bearer {{accessToken}}
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,674 questions
{count} votes

Accepted answer
  1. Tianyu Sun-MSFT 27,796 Reputation points Microsoft Vendor
    2023-03-02T12:51:09.4566667+00:00

    Hello @Oleksii Kovalchuk ,

    Welcome to Microsoft Q&A forum.

    It’s pretty awesome feature, but it’s not documented. There are similar tools/extensions docs, but as I can see – it’s a built-in tool rather than extension.

    Yes, this is a new feature in VS 2022 version 17.5. This blog Modern .NET and Cloud development API development inner-loop introduces this new feature.

    It has variables support in general, but what about request variables?

    As the blog states "This is just our first step towards improving the quality-of-life for developers working with microservices in Visual Studio – stay tuned for future features in upcoming previews!", this new feature is still improving. I may suggest you directly submit a ticket(suggestion/feedback) on our Developer Community. I will also help to report your feedback.

    Please feel free to let us know if you have any other concerns.

    Sincerely,

    Tianyu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful