REST-API commands via Visual Studio Code and Thunder Client
1. Introduction
This guide shows how to send HTTP commands to a REST-API client using the Thunder Client plug-in in Visual Studio Code.
2. Visual Studio Code Plug-In "Thunder Client"
Attention:
In principle, none of the actions can be undone throughout the plug-in.
Changes are only valid after saving (CTRL + S).
2.1. Installation Plug-In
Click on the "Extensions" tab on the left-hand side and search for "Thunder Client".
Click on the blue "Install" button to install the extension, which will also appear as a separate tab on the left-hand side.
If the tab for the Thunder Client does not appear, it is due to the restricted mode when restarting:
Click on the Restricted Mode field and then confirm under "Trust"
2.2. Use
- List of recent commands
- Library of commands: Collections
Predefined commands can be imported or exported into packages here.
Please note: The free version can only contain 50 commands per collection.
- Type of command: GET, POST, DELETE, etc.
- Header customization
Additional header information can be added to the free field:
Example: Send cookie in the header information:
- Authentication
Additional information on different authentication methods can be added here
Ex: Bearer Token
Ex: Basic Authetification
Is transmitted in the header in the format usaername:password in Base64 format.
Attention: cannot be used for user login!
- Body information with different data formats
Sending files: - Sending the command
- Response to the command
Here is an example of the response to a login process.
1. Direct response:
2. Header information
3. Cookies (separated):
4. Analyze request:
3. Variables
There are three types of variables:
Path variables: {{variable}}
Environment variables: {{variable}}
System variables: {{#Variable}}
Environment variables can be defined in the Env tab.
Example: Login with environment variables
- Log in and retrieve bearer token
- Customize environment variable:
Attention: Do not forget to save! - Use variable in POST command:
Attention:
The values of the variables are assigned in sequence.
If a variable exists more than once (no check of the editor!), the value of the lowest variable is always assigned,
Example: Here the variable PortNumber is assigned the value 1.
3.1. Path variables
Path variables are displayed between a single curly bracket.
These can be assigned to a command in the Query tab.
3.2. Environment variables
Environment variables can be defined in the Env tab.
Example: Login with environment variables
- Log in and retrieve Bearer Token
- Customize environment variable:
Attention: Do not forget to save! - Use variable in POST command:
Attention:
The values of the variables are assigned in sequence.
If a variable exists more than once (no check of the editor!), the value of the lowest variable is always assigned,
Example: Here the variable PortNumber is assigned the value 1.
Only one variable list can be active at a time.
You can swap between the variable tables at the bottom of the development environment:
3.3. System variables
System variables are displayed in a double curly bracket and also have a hash {{#variable}}.
Example: Setting the system time using a system variable
Example: Randomly generated values for names, strings or emails
3.4. Automation of processes
A distinction is made between pre-requests and POST requests, which can be sent automatically to a certain extent.
Javascript programs can also be played before or after.
Pre-requests are commands and requests that can be sent before the actual command is sent.
Example: Query whether you are logged in. If not, login is executed.
Scripting example:
Post-requests are sent or processed after the actual command has been executed.
Example: Setting variables.
Example: Checking the command response.
Example scripting: Evaluate response.
Scripting
4. Collections
Predefined collections or YAML files can be inserted via Import.
Each collection can be provided with global settings that affect every command and folder.
A base path can be specified under Options, which is placed in front of each command in the collection.
BaseURL and BasePath are stored here.
Example:
192.168.1.1/api/balluff/v2
The rest of the specific command is defined by the respective command input.
If external APIs are loaded via a YAML file, for example, variables may have to be adapted in the command:
As here, an additional {} must be inserted so that this is recognized as a variable of the Env table.
Attention: Each collection can only contain 50 commands in the free version!