VS Code REST Client Cheat Sheet
Sidebar
Programming · VS Code REST Client Cheat Sheet
Sending HTTP requests from a text file inside VS Code: the request format, variables, environments, authentication, commands and settings. Checked against REST Client 0.25.1 installed here. Sheet 21 in the VS Code series. Handy for trying out a FastAPI or other web API without leaving the editor.
Getting Started & Shortcuts
Extension IDhumao.rest-client (version 0.25.1 here)File typeSave requests in a .http or .rest file (language mode HTTP)Send Request (link)A clickable link above each request in HTTP modeCtrl+Alt+RSend the request at the cursor, or the selected textCtrl+Alt+LRerun the last request (also from the response panel)Ctrl+Alt+KCancel a request that is still waitingCtrl+Alt+HView request historyCtrl+Alt+ESwitch environmentCtrl+Alt+CGenerate a code snippet for the request###A line of three or more # separates requests in one fileHover the status barHover the time to see the DNS, TCP, first-byte and download breakdown; hover the size for headers and bodyWriting a Request
GET https://example.com/itemsMethod, URL; HTTP/1.1 is optional, and a bare URL means GETQuery string over several linesPut ?page=2 and &pageSize=10 on indented lines below the request lineHeader: valueHeader lines follow the request line, up to the first blank line(blank line) bodyEverything after the first blank line is the request body< ./body.jsonUse a file as the body (path absolute, or relative to the workspace or the file)<@ ./body.jsonSame, but substitute {{variables}} inside the file; add an encoding as in <@latin1multipart/form-dataWrite boundary-separated parts; file parts use < ./file.pngx-www-form-urlencodedOne name=value per line, continuing lines start with &X-REQUEST-TYPE: GraphQLHeader that makes the body a GraphQL query, with variables as JSON after a blank linecurl commandPaste a curl command and send it (supports -X, -L, -H, -I, -b, -u, -d)# comment or // commentCommentsVariables: Kinds and Syntax
{{name}}Use a custom variable; system variables use {{$name}}Environment variableDefined in settings under rest-client.environmentVariables; changes with the chosen environment@name = valueFile variable: a whole line anywhere in the file; can use other variables# @prompt name DescriptionPrompt variable: you are asked for the value each time you send# @name loginNames a request so later requests can use its response{{login.response.body.$.token}}Use a part of a named request's response: JSONPath in the body{{login.response.headers.X-AuthToken}}Use a response header{{x.response.body.//reply[1]/@id}}XPath works for XML bodiesUnresolved referenceThe plain text is sent instead, and a diagnostic appearsSystem Variables
{{$guid}}A new random UUID{{$randomInt 5 200}}A random whole number from 5 up to (not including) 200{{$timestamp}}Now as a Unix timestamp; {{$timestamp -1 d}} is one day ago{{$datetime iso8601}}Now in UTC as iso8601, rfc1123 or a quoted custom format like 'YYYY-MM-DD'{{$localDatetime 'YYYY-MM-DD'}}The same in your local time zone{{$processEnv NAME}}A value from your operating system's environment (good for secrets){{$processEnv %secretKey}}With %, look up the environment variable whose name is stored in your REST Client environment setting{{$dotenv NAME}}A value from a .env file next to the .http fileOffset unitsy, M, w, d, h, m, s, ms{{$aadToken}} {{$aadV2Token}}Azure Active Directory tokens, with options such as new and scopes:Authentication
Authorization: Basic user:passwdBasic auth; the extension encodes it. Also accepted: Basic user passwd or an already base64-encoded valueAuthorization: Digest user passwdDigest authrest-client.certificatesClient certificates per host, e.g. { "localhost:8080": { "pfx": "./client.pfx", "passphrase": "…" } } (default {})Azure AD / AWS Signature v4Supported; see the extension's README for the exact syntaxKeep secrets out of the fileUse {{$processEnv …}}, {{$dotenv …}} or a user setting, never a token typed into a committed .http fileEnvironments
rest-client.environmentVariables{ "$shared": {…}, "local": {…}, "production": {…} }$sharedVariables available in every environment; an environment's own value wins on a clashRest Client: Switch EnvironmentCommand Palette or Ctrl+Alt+E; the current one shows in the status bar{{$shared name}}Refer to a shared variable from inside an environment's valueNo EnvironmentChoose it to use only file and request variablesBehaviour Settings (rest-client.*)
rest-client.followredirectFollow 3xx responses (default true); per request: # @no-redirectrest-client.defaultHeadersAdded when you omit them (default { "User-Agent": "vscode-restclient" })rest-client.timeoutinmillisecondsRequest timeout; 0 (default) means wait foreverrest-client.rememberCookiesForSubsequentRequestsKeep cookies between requests (default true); per request: # @no-cookie-jarrest-client.excludeHostsForProxyHosts that skip the VS Code proxy settings (default [])rest-client.formParamEncodingStrategyautomatic (default), never, always: URL-encode form valuesrest-client.decodeEscapedUnicodeCharactersShow \u00e9-style escapes as real characters (default false)rest-client.addRequestBodyLineIndentationAroundBracketsAuto-indent inside { } when you press Enter (default true)rest-client.enableTelemetryAnonymous usage data (default true)rest-client.logLevelerror (default), warn, info, verbose in the REST output panelrest-client.enableSendRequestCodeLensThe Send Request link (default true)rest-client.enableCustomVariableReferencesCodeLensA references count above variables (default true)Response Preview
rest-client.previewOptionfull (default), headers, body, exchange (request and response)rest-client.previewColumnbeside (default) or current: where the response opensrest-client.previewResponsePanelTakeFocusMove focus to the response (default true)rest-client.showResponseInDifferentTabA new tab for each response (default false)rest-client.requestNameAsResponseTabTitleTitle the tab with the request's # @name (default false)rest-client.previewResponseInUntitledDocumentOpen responses as plain untitled documents (default false)rest-client.fontSize / fontFamily / fontWeightStyle of the response panel (default: the extension's own; 0 size follows the editor)rest-client.largeResponseBodySizeLimitInMBResponses over this size count as large (default 5)rest-client.disableHighlightResonseBodyForLargeResponseNo syntax colours for large responses (default true)rest-client.disableAddingHrefLinkForLargeResponseNo clickable links in large responses (default true)rest-client.suppressResponseBodyContentTypeValidationWarningHide the content-type mismatch warning (default false)rest-client.mimeAndFileExtensionMappingFile extensions for saved bodies, e.g. { "application/atom+xml": "xml" }rest-client.useContentDispositionFilenameName saved files from the content-disposition header (default true)Commands (Rest Client: …)
Send Request / Rerun Last Request / Cancel RequestRun, repeat or stop a requestView Request History / Clear Request HistoryEvery sent request is stored; ask for it again from the history listSwitch EnvironmentPick the active environmentSave Full Response / Save Response BodySave the whole response, or just the body, to a fileCopy Response BodyCopy the body to the clipboardGenerate Code Snippet / Copy Code SnippetTurn the request into code in many languages and librariesCopy Request As cURLGet an equivalent curl command (also on the right-click menu)Fold Response / Unfold ResponseCollapse or expand the response bodyClear Azure AD Token CacheForget cached Azure tokens# @notePer-request: ask for confirmation before sending (for risky requests)A Sample File to Copy (adjust to your API)
@host = http://localhost:8000A file variable for the base address (FastAPI's default dev port)# @name healthNames the request that followsGET {{host}}/healthA simple GET using the variablePOST {{host}}/itemsFollowed by Content-Type: application/json, a blank line, then a JSON bodyGET {{host}}/items/{{create.response.body.$.id}}Uses the id returned by an earlier request named create###Separator between requestsCtrl+Alt+K may clash with the Claude Code extension
REST Client uses Ctrl+Alt+K to cancel a request in an HTTP file, and the Claude Code extension also binds Ctrl+Alt+K (insert the current selection as a reference) whenever an editor has focus. If cancel does not work, open the Keyboard Shortcuts editor (Ctrl+K Ctrl+S), search for ctrl+alt+k, and give one of them a different key, or use the cancel link or Rest Client: Cancel Request from the Command Palette instead.
Never commit real tokens in a .http file
A request file is plain text and usually lives in your project, so anything typed into it ends up in Git. Put secrets in a .env file (listed in .gitignore) and read them with {{$dotenv NAME}}, or read them from the operating system with {{$processEnv NAME}}. Environments defined in your user settings stay out of the repository, but those in a workspace .vscode/settings.json are committed with it.