REST Client allows you to send HTTP request and view the response in Visual Studio Code directly.
- Send/Cancel/Rerun HTTP request in editor and view response in a separate pane with syntax highlight
- Send CURL command in editor and copy HTTP request as
CURL command - Auto save and view/clear request history
- Support MULTIPLE requests in the same file
- View image response directly in pane
- Save raw response and response body only to local disk
- Customize font(size/family/weight) in response preview
- Authentication support for:
- Basic Auth
- Digest Auth
- SSL Client Certificates
- Environments and custom/global system variables support
- Use custom/global variables in any place of request(URL, Headers, Body)
- Support both environment and file custom variables
- Auto completion and hover support for both environment and file custom variables
- Go to definition and find all references support ONLY for file custom variables
- Provide system dynamic variables
{{$guid}},{{$randomInt min max}}and{{$timestamp}} - Easily create/update/delete environments and custom variables in setting file
- Support environment switch
- Generate code snippets for HTTP request in languages like
Python,Javascriptand more! - Remember Cookies for subsequent requests
- Proxy support
- Send SOAP requests, as well as snippet support to build SOAP envelope easily
HTTPlanguage support.httpand.restfile extensions support- Syntax highlight (Request and Response)
- Auto completion for method, url, header, custom/global variables, mime types and so on
- Comments (line starts with
#or//) support - Support
jsonandxmlbody indentation, comment shortcut and auto closing brackets - Code snippets for operations like
GETandPOST
In editor, type a HTTP request as simple as below:
https://example.com/comments/1Or, you can follow the standard RFC 2616 that including request method, headers and body.
POST https://example.com/comments HTTP/1.1
content-type: application/json
{
"name": "sample",
"time": "Wed, 21 Oct 2015 18:27:50 GMT"
}Once you prepared a request, click the Send Request link above the request, or use shortcut Ctrl+Alt+R(Cmd+Alt+R for macOS), or right click in the editor and then select Send Request in the menu, or press F1 and then select/type Rest Client: Send Request, the response will be previewed in a separate webview panel of Visual Studio Code. If you'd like to use the full power of searching, selecting or manipulating in Visual Studio Code, you can also preview response in an untitled document by setting rest-client.previewResponseInUntitledDocument to true, by default the value is false. When a request is issued,
will be displayed in the status bar, after receiving the response, the icon will be changed to the duration and response size. When hovering over the duration status bar, you could view the breakdown duration details of Socket, DNS, TCP, First Byte and Download. When hovering over the response size status bar, you could view the breakdown response size details of headers and body.
All the shortcuts in REST Client Extension are ONLY available for file language mode
httpandplaintext.
You may even want to save numerous requests in the same file and execute any of them as you wish easily. REST Client extension could recognize any line begins with three or more consecutive # as a delimiter between requests. Place the cursor anywhere between the delimiters, issuing the request as above, and it will first parse the text between the delimiters as request and then send it out.
GET https://example.com/comments/1 HTTP/1.1
###
GET https://example.com/topics/1 HTTP/1.1
###
POST https://example.com/comments HTTP/1.1
content-type: application/json
{
"name": "sample",
"time": "Wed, 21 Oct 2015 18:27:50 GMT"
}REST Client Extension also provides another flexibility that you can use mouse to highlight the text in file as request text.
Press F1, type ext install rest-client.
The first non-empty line of the selection (or document if nothing is selected) is the Request Line. Below are some examples of Request Line:
GET https://example.com/comments/1 HTTP/1.1GET https://example.com/comments/1https://example.com/comments/1If request method is omitted, request will be treated as GET, so above requests are the same after parsing.
You can always write query strings in the request line, like:
GET https://example.com/comments?page=2&pageSize=10Sometimes there may be several query parameters in a single request, putting all the query parameters in Request Line is difficult to read and modify. So we allow you to spread query parameters into multiple lines(one line one query parameter), we will parse the lines in immediately after the Request Line which starts with ? and &, like
GET https://example.com/comments
?page=2
&pageSize=10The lines immediately after the request line to first empty line are parsed as Request Headers. Please provide headers with the standard field-name: field-value format, each line represents one header. By default REST Client Extension will add a User-Agent header with value vscode-restclient in your request if you don't explicitly specify. You can also change the default value in setting rest-client.defaultuseragent.
Below are examples of Request Headers:
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/jsonIf you want to provide the request body, please add a blank line after the request headers like the POST example in usage, and all content after it will be treated as Request Body. Below are examples of Request Body:
POST https://example.com/comments HTTP/1.1
Content-Type: application/xml
Authorization: token xxx
<request>
<name>sample</name>
<time>Wed, 21 Oct 2015 18:27:50 GMT</time>
</request>You can also specify file path to use as a body, which starts with < , the file path can be either in absolute or relative(relative to workspace root or current http file) formats:
POST https://example.com/comments HTTP/1.1
Content-Type: application/xml
Authorization: token xxx
< C:\Users\Default\Desktop\demo.xmlPOST https://example.com/comments HTTP/1.1
Content-Type: application/xml
Authorization: token xxx
< ./demo.xmlWhen content type of request body is multipart/form-data, you may have the mixed format of the request body like following:
POST https://api.example.com/user/upload
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="text"
title
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="image"; filename="1.png"
Content-Type: image/png
< ./1.png
------WebKitFormBoundary7MA4YWxkTrZu0gW--
We add the capability to directly run curl request in REST Client extension. The issuing request command is the same as raw HTTP one. REST Client will automatically parse the request with specified parser.
Sometimes you may want to get the curl format of a http request quickly and save it to clipboard, just pressing F1 and then selecting/typing Rest Client: Copy Request As cURL or simply right click in the editor, and select Copy Request As cURL.
Once you want to cancel a processing request, use shortcut Ctrl+Alt+Q(Cmd+Alt+Q for macOS), or press F1 and then select/type Rest Client: Cancel Request.
Sometimes you may want to refresh the API response, now you could do it simply using shortcut Ctrl+Alt+L(Cmd+Alt+L for macOS), or press F1 and then select/type Rest Client: Rerun Last Request to rerun last request.
Each time we sent a http request, the request details(method, url, headers and body) would be persisted into file. By using shortcut Ctrl+Alt+H(Cmd+Alt+H for macOS), or press F1 and then select/type Rest Client: Request History, you can view the last 50 request items(method, url and request time) in the time reversing order, you can select any request you wish to trigger again. After specified request history item is selected, the request details would be displayed in a temp file, you can view the request details or follow previous step to trigger the request again.
You can also clear request history by pressing F1 and then selecting/typing Rest Client: Clear Request History.
In the upper right corner of the response preview tab, we add a new icon to save the latest response to local file system. After you click the Save Response icon, it will prompt the window with the saved response file path. You can click the Open button to open the saved response file in current workspace, or click Copy Path to copy the saved response path to clipboard.
Another icon in the upper right corner of the response preview tab is the Save Response Body button, it will only save the response body ONLY to local file system. The extension of saved file is set according to the response MIME type, like if the Content-Type value in response header is application/json, the saved file will have extension .json. You can also overwrite the MIME type and extension mapping according to your requirement with the rest-client.mimeAndFileExtensionMapping setting.
"rest-client.mimeAndFileExtensionMapping": {
"application/atom+xml": "xml"
}We have supported some most common authentication schemes like Basic Auth, Digest Auth and SSL Client Certificates.
HTTP Basic Auth is a widely used protocol for simple username/password authentication. We support two formats of Authorization header to use Basic Auth.
- Add the value of Authorization header in the base64 encoding of
username:password. - Add the value of Authorization header in the raw value of
usernameandpassword, which is separated by space.
The corresponding examples are as following:
GET https://httpbin.org//basic-auth/user/passwd HTTP/1.1
Authorization: Basic dXNlcjpwYXNzd2Q=and
GET https://httpbin.org//basic-auth/user/passwd HTTP/1.1
Authorization: Basic user passwdHTTP Digest Auth is also a username/password authentication protocol that aims to be slightly safer than Basic Auth. The format of Authorization header for Digest Auth is similar to Basic Auth. You just need to set the scheme to Digest, as well as the raw user name and password.
GET https://httpbin.org/digest-auth/auth/user/passwd
Authorization: Digest user passwdWe support PFX, PKCS12, and PEM certificates. Before using your certificates, you need to set the certificates paths(absolute/relative to workspace/relative to current http file) in the setting file for expected host name(port is optional). For each host, you can specify the key cert, key, pfx and passphrase.
cert: Path of public x509 certificatekey: Path of private keypfx: Path of PKCS #12 or PFX certificatepassphrase: Optional passphrase for the certificate if required You can add following piece of code in your setting file if your certificate is inPEMformat:
"rest-client.certificates": {
"localhost:8081": {
"cert": "/Users/demo/Certificates/client.crt",
"key": "/Users/demo/Keys/client.key"
},
"example.com": {
"cert": "/Users/demo/Certificates/client.crt",
"key": "/Users/demo/Keys/client.key"
}
}Or if you have certificate in PFX or PKCS12 format, setting code can be like this:
"rest-client.certificates": {
"localhost:8081": {
"pfx": "/Users/demo/Certificates/clientcert.p12",
"passphrase": "123456"
}
}
Once you’ve finalized your request in REST Client extension, you might want to make the same request from your own source code. We allow you to generate snippets of code in various languages and libraries that will help you achieve this. Once you prepared a request as previously, use shortcut Ctrl+Alt+C(Cmd+Alt+C for macOS), or right click in the editor and then select Generate Code Snippet in the menu, or press F1 and then select/type Rest Client: Generate Code Snippet, it will pop up the language pick list, as well as library list. After you selected the code snippet language/library you want, the generated code snippet will be previewed in a separate panel of Visual Studio Code, you can click the Copy Code Snippet icon in the tab title to copy it to clipboard.
Add language support for HTTP request, with features like syntax highlight, auto completion and comment support, when writing HTTP request in Visual Studio Code. By default, the language association will be automatically activated in two cases:
- File with extension
.httpor.rest - First line of file follows standard request line in RFC 2616, with
Method SP Request-URI SP HTTP-Versionformat
If you want to enable language association in other cases, just change the language mode in the right bottom of Visual Studio Code to HTTP.
Currently auto completion will be enabled for following seven categories:
- HTTP Method
- HTTP URL from request history
- HTTP Header
- Global dynamic variables
- Custom variables in current environment/file
- MIME Types for
AcceptandContent-Typeheaders - Authentication scheme for
BasicandDigest
Environments give you the ability to customize requests using variables, and you can easily switch environment without changing requests in http file. A common usage is having different configurations for different product environments, like devbox, sandbox and production.
Environments and corresponding variables of REST Client Extension are defined in setting file of Visual Studio Code, so you can create/update/delete environments and variables at any time you wish. The changes will take effect right away. If you DO NOT want to use any environment, you can choose No Environment in the environments list. See here for more details about environment variables usage and other kinds of variables. Below is a sample piece of setting file for custom environments and environment level variables:
"rest-client.environmentVariables": {
"local": {
"host": "localhost",
"token": "test token"
},
"production": {
"host": "example.com",
"token": "product token"
}
}A sample usage in http file for above custom variables is listed below:
GET https://{{host}}/api/comments/1 HTTP/1.1
Authorization: {{token}}We support two types of variables, one is Global System Variables which is a predefined set of variables out-of-box, another is Custom Variables which is defined by user and can even be divided into Environment Variables and File Variables.
The usage of these two types of variables also has a little difference, for the former the syntax is {{$SystemVariableName}}, while for the latter, no matter environment or file level custom variables, the syntax is {{CustomVariableName}}.
Custom variables belong to either the environment or file scope. The environment scope variables are mainly used for storing values that vary in different environments and keep unchanged in an specific environment. And environment variables are defined in vscode setting file which can be used across of different files. The file scope variables are mainly used for variables which are frequently updated variables and not so common across environments. And file variables are directly defined in http file, which can be update and share with others much easily.
For environment variables, each environment is a set of key value pairs defined in setting file, key is the variable name, while value is variable value. Only custom variables in selected environment are available to you. Current active environment name is displayed in the right bottom of Visual Studio Code, when you click it, you can switch environment, current active environment's name will be marked with a check sign in the end. And you can also switch environment using shortcut Ctrl+Alt+E(Cmd+Alt+E for macOS), or press F1 and then select/type Rest Client: Switch Environment. When you write custom variables in http file, auto completion will be available to you, so if you have a variable named host, you don't need to type the full word {{host}} by yourself, simply type host or even less characters, it will prompt you the host variable as well as its actual value. After you select it, the value will be autocompleted with {{host}}. And if you hover on it, its value will also be displayed.
For file variables, each variable definition follows syntax @variableName = variableValue. And variable name MUST NOT contains any spaces. As for variable value, it can be consist of any characters, even white spaces are allowed for them (Leading and trailing white spaces will be ignored). And variables can be defined in a common block of code which is also separated by ###. You can also define them before any request url, which needs an extra blank line between variable definitions and request url. However, no matter where you define the variables in the http file, they can be referenced in any requests of the file. For file scope variables, you can also benefit from some Visual Studio Code features like Go to definition and Find All References.
@name = Huachao Mao
@id = 313
###
@token = Bearer e975b15aa477ee440417ea069e8ef728a22933f0
GET https://example.com/api/comments/1 HTTP/1.1
Authorization: {{token}}
###
PUT https://example.com/api/comments/{{id}} HTTP/1.1
Authorization: {{token}}
Content-Type: application/json
{
"name": "{{name}}"
}When same name variable defined in both environment and file scope, file scope variable has precedence over environment scope variable. That means the extension will use the variable value defined in
httpfile.
Global variables provide a pre-defined set of variables that can be used in any part of the request(Url/Headers/Body) in the format {{$variableName}}. Currently, we provide a few dynamic variables which you can use in your requests. The variable names are case-sensitive.
{{$guid}}: Add a RFC 4122 v4 UUID{{$randomInt min max}}: Returns a random integer between min (included) and max (excluded){{$timestamp}}: Add UTC timestamp of now. You can even specify any date time based on current time in the format{{$timestamp number option}}, e.g., to represent 3 hours ago, simply{{$timestamp -3 h}}; to represent the day after tomorrow, simply{{$timestamp 2 d}}. The option string you can specify in timestamp are:
| Option | Description |
|---|---|
| y | Year |
| Q | Quarter |
| M | Month |
| w | Week |
| d | Day |
| h | Hour |
| m | Minute |
| s | Second |
| ms | Millisecond |
@token = Bearer fake token
POST https://{{host}}/comments HTTP/1.1
Content-Type: application/xml
X-Request-Id: {{token}}
{
"request_id": "{{$guid}}",
"updated_at": "{{$timestamp}}",
"created_at": "{{$timestamp -1 d}}",
"review_count": "{{$randomInt 5, 200}}"
}REST Client Extension adds the ability to control the font family, size and weight used in the response preview.
rest-client.followredirect: Follow HTTP 3xx responses as redirects. (Default is true)rest-client.defaultuseragent: If User-Agent header is omitted in request header, this value will be added as user agent for each request. (Default is vscode-restclient)rest-client.timeoutinmilliseconds: Timeout in milliseconds. 0 for infinity. (Default is 0)rest-client.showResponseInDifferentTab: Show response in different tab. (Default is false)rest-client.rememberCookiesForSubsequentRequests: Save cookies fromSet-Cookieheader in response and use for subsequent requests. (Default is true)rest-client.enableTelemetry: Send out anonymous usage data. (Default is true)rest-client.excludeHostsForProxy: Excluded hosts when using proxy settings. (Default is [])rest-client.fontSize: Controls the font size in pixels used in the response preview. (Default is 13)rest-client.fontFamily: Controls the font family used in the response preview. (Default is Menlo, Monaco, Consolas, "Droid Sans Mono", "Courier New", monospace, "Droid Sans Fallback")rest-client.fontWeight: Controls the font weight used in the response preview. (Default is normal)rest-client.environmentVariables: Sets the environments and custom variables belongs to it (e.g.,{"production": {"host": "api.example.com"}, "sandbox":{"host":"sandbox.api.example.com"}}). (Default is {})rest-client.mimeAndFileExtensionMapping: Sets the custom mapping of mime type and file extension of saved response body. (Default is {})rest-client.previewResponseInUntitledDocument: Preview response in untitled document if set to true, otherwise displayed in html view. (Default is false)rest-client.previewResponseSetUntitledDocumentLanguageByContentType: Attempt to automatically set document language based on Content-Type header when showing each response in new tab. (Default is false)rest-client.includeAdditionalInfoInResponse: Include additional information such as request URL and response time when preview is set to use untitled document. (Default is false)rest-client.certificates: Certificate paths for different hosts. The path can be absolute path or relative path(relative to workspace or current http file). (Default is {})rest-client.useTrunkedTransferEncodingForSendingFileContent: Use trunked transfer encoding for sending file content as request body. (Default is true)
Rest Client respects the proxy settings made for Visual Studio Code (http.proxy and http.proxyStrictSSL).
See CHANGELOG here
All the amazing contributors❤️
Please provide feedback through the GitHub Issue system, or fork the repository and submit PR.

