VSCodeVSCode extension of the day: Rest Client
Domenico Solazzo
- undefined min
Tired to move back and forth between your editor and the tools that you use for testing http requests? There is a solution to this issue.
The extension of the day is called REST Client.
Let’s start and see what it can do. After installing from the VSCode marketplace, you can notice the simplicity of this extension.
Create a new tab, paste a raw HTTP request and you are ready to send your first HTTP request from your editor.
Which kind of requests can we send using this extension?Try to paste in your editor a simple HTTP GET request like so:
GET https://www.medium.com/@domenicosolazzo
Click Command+Option+R on your Mac (Ctrl+Alt+R for Windows), and the response of the server should appear in another pane in your editor.
That was easy. What else can you customize in your request?
You can have more control over your request and change anything you want in both the HTTP header and the HTTP message body.
In case you want to change the Request Headers, please provide headers with the standard field-value format. One line per header.
You can see some example of headers that you add to your request:
User-Agent: rest-client
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6,zh-CN;q=0.4
Content-Type: application/json
If you want to provide the request body, please add a blank line after the request headers.
All the content after will be treated as a Request Body.
The body could be a XML or JSON snippet, plaintext or even a local file in your machine.
Let’s see some more request that you can copy-paste in VSCode. In the first example, we will send an XML snippet.
POST https://www.example.com/sitemap HTTP/1.1
Content-Type: application/xml
Authorization: token <add your authorization token here>
<site>
<name>Domenico Solazzo</name>
<url>https://www.domenicosolazzo.com</city>
</site>
In case you want to send a local file, start with < and then the file path (absolute or relative)…you can also do that!
POST https://www.example.com/profile HTTP/1.1
Content-Type: application/json
Authorization: token <add your authorization token here>
< /users/domenicosolazzo/profile.json
Well, you got the point. Form data, JSON data, XML data, Plaintext, from local files or not..you decide!
Pretty powerful.
That’s all? No, there are much more features that I will not describe here but…
I want to talk about a cool feature of REST Client: cURL. Well, cURL is not a feature of this REST Client but it can be used inside this extension.
I used cURL quite a lot in my daily life as programmer and what if you have a cURL request already in your terminal and you want to run it in your editor?
Yes, correct! You can also do that.
You can also do the opposite. If you have already a raw HTTP request in your editor, you can copy the request as cURL.
Just press F1 and then selecting/typing Rest Client: Copy Request As cURL or simply right-click in the editor, and select Copy Request As cURL.
Last, but not least feature is the ability to create code snippets for your favorite programming language, such as Go, JS, Node, C#, etc…
// NodeJS Example for the request: GET http://www.domenicosolazzo
var request = require("request");
var options = { method: 'GET', url: 'https://www.domenicosolazzo.com/' };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
And you can do much more: check all the features in the official marketplace page: Rest Client
This is a great extension if you want to test the your http request in your editor without switching to Postman or similar tools.
I love this extension and I would really recommend it if you are a developer.
Your choice. I much prefer in this way!
Well, that’s all for today!
What is your favourite Editor extension and why?
Do you know that I have a YouTube channel? Subscribe!
Where can you find me?
These are my blog articles
Domenico Solazzo
Domenico Solazzo
Domenico Solazzo