VS Code quickly established itself in the IT market as a comprehensive programming environment for practically every technology. Above all, Microsoft made it available for free, disrupting the hobbyist market that didn’t need a paid environment. Additionally, the open-source nature led to the community enthusiastically enhancing Code with an open extension interface.
In my daily work, VS Code primarily serves as a quick programming notepad with syntax highlighting and a set of tools useful in everyday tasks. Today, I’d like to showcase the latter aspect. What if VS Code replaced our dedicated tools for REST interfaces?
Chinese developer Huachao Mao published the REST Client extension in the marketplace in 2016, and it quickly climbed the ranks of the most popular VS Code add-ons. Currently, it is, in my opinion, one of the more interesting extensions that have appeared in the Marketplace.
To install the plugin, simply search for it in the Extensions tab and click install.
To start using the REST Client, we need to create a file with the extension .http
or .rest
and invoke a sample endpoint using the RFC 2616 protocol syntax.
After clicking the “Send Request” button, we’ll receive a response from the server.
If we want to include more than one HTTP request in a single document, we can separate them with a triple hash (###
).
Variables are defined using @
. We can refer to:
{{$randomInt min max}}
DOTNET_ENVIRONMENT
If we want to make a POST request and create a resource, we only need to specify the appropriate HTTP headers and the request body. We can also load the body from a file.
Another feature worth knowing is the ability to generate cURL requests for our queries. Simply run the Command Palette (default F1) and execute the command Rest Client: Copy Request As cURL
.
This way, we can use cURL in the command line.
Since GraphQL is also transported via the HTTP protocol, we can query graph APIs using VSCode.
The extension also allows generating code snippets for the endpoints in the file. The supported list of languages is extensive, including Java, C#, JavaScript, Python, etc.
In my opinion, the ability to create files with REST requests opened a gateway to keep a basic test set for endpoints in the repository, eliminating the need to run another tool.
Moreover, since they are formally test files, it is relatively easy to version your or team’s handy set of queries.