REST Book
REST Book is a Visual Studio Code extension that allows you to perform REST calls in a Notebook interface.
Features
- Create and run REST Calls within cells.
- Organize multiple REST Calls within one file.
- Intermingle markdown for documenting your calls.
- View rich HTML and image responses directly inside the Notebook.
- Optionally use the Interactive Window interface.
- Basic Authentication.
- Use data from one call in the next.
- Save API keys and other sensitive information outside of the Notebook to use securely in calls.
Requirements
Must be using the latest version of Visual Studio Code Insiders edition.
Usage
- Create a new file to store your REST Calls with a
.restbook
ending.
You can also use the command: REST Book: Create a new blank REST Notebook
.
- Add a code cell by hovering over the middle of the Notebook and clicking the
+ Code
- Add your intended URL as the first line of the cell. By default without specifying a method, it will be a GET call.
To use the Interactive Window interface:
- Run the command:
REST Book: Create an Interactive Window
- Enter your line(s) into the input field at the bottom of the window.
- Click the adjacent button to run them.
- Repeat.
Changing output view to rich rendered HTML or rich JSON view
To toggle between the different views for the results of calls you can change mimetype like so:
More examples
google.com
is equivalent to:
GET google.com
Parameters
In subsequent lines immediately following the first line add any parameters or queries starting with ?
or &
like this:
GET https://www.google.com
?query="fun"
&page=2
In the lines following without an empty line will be considered as the Request Headers:
GET https://www.google.com
?query="fun"
&page=2
User-Agent: rest-book
Content-Type: application/json
Bodies
The last lines after a new line separator is the body of the call. Like the following:
POST https://www.myapi.com
User-Agent: rest-book
Content-Type: application/json
{
name: "Foo",
text: "Foo is the most bar of the Foos"
}
Or you can load the body from another file like so:
POST https://www.myapi.com
User-Agent: rest-book
Content-Type: application/json
./body.txt
Variables
You can also assign the responses from calls to a variable and use the data from that response in future calls. To do this you would just declare a variable with let
and the name of your variable and then a =
like so:
let foo = GET google.com
And then in future cells you can reference foo
in your calls with a $
sign. Here's a short example:
Using API keys and other secrets
If you'd like to use secret information in your calls like API keys but you don't want to use and save the raw text of these keys in the REST Notebooks, you can use secrets to save and access API keys.
To save secrets, look for the command REST Book: Secrets
in the command palette with Cmd+Shift+P (MacOS) or Ctrl+Shift+P (Windows). Add a new secret and a name for that secret.
Then when use your secrets in your calls using the $SECRETS
variable. In this example I'm saving a secret with the name mySecret
and then accessing this secret to send to my Express server with $SECRETS.mySecret
. You can see my server received my secret value of "hooray" correctly but the secret text is not visible anywhere in the Notebook.
And you can see that the actual secret is not saved in the results of the call. Every place that used a secret will be replaced by [Secret <secret name>]
; this is for all parameters, headers, and bodies sent. Here you can see that my secret text "hooray" was replaced by [Secret mySecret]
in the view of the request I sent.
To test these interactions, you can play around with this simple server: SandboxServer
Known Issues
Unable to save responses. This should be fixed soon in the next few versions of VS Code Insiders.
Any Other issues
Please submit your issue on the tanhakabir/rest-book repository with exact reproduction steps.