Send Request from VSCode with Rest Client Extension

Tram Ho

Feature

  • Send/Cancel/Rerun the HTTP request in the editor and view the response in a separate pane with syntax highlighting
  • Submit GraphQL queries and author GraphQL variables in the editor
  • Send cURL command in editor and copy HTTP request as cURL command
  • Automatically save and view/delete request history
  • Compose MULTIPLE requests in one file (separated by ### delimiter)

Go to extensions of VSCode instal Rest client => create file demo.http

Use

There are 2 ways to create a request variable

  • Create variable in file http: @host = https://demo.vn
  • Create variable in settings.json file of VSCode
    1. Click the settings button in the lower left corner of VSCode
    2. In the search box type: rest client => click Edit in settings.json Screen Shot 2022-12-24 at 10.57.01.png
    3. In the settings.json file => find the word rest-client.environmentVariables and then declare the variable in $shared

Create a name for requests

  • The request is called login => put a pound sign at the beginning of the line => @name => request name

Request url includes

  • Method ( GET/POST/PATCH/DELETE)
  • Url: as shown in the picture is {{host}}/api/users/token/ with host as the variable declared above
  • Params:

  • Body:

Get value from response Like the 3rd line of the figure in the feature section we assign access from the response of the request named login to the token variable This token variable will automatically receive the value when the login request is triggered

Assign authorization token to request

With ### in between requests to help separate requests from each other

Share the news now

Source : Viblo