Visual Studio Code Rest Client

Hey guys, how you doing?

This week on twitter, I found this post from @code (The Visual Studio Code guys):

http://josephwoodward.co.uk/2017/10/rest-%20client-for-vs-code-an-elegant-alternative-postman

I’m a Postman regular user, but, this solution is pretty elegant and super easy to share with your work colleagues!

I think the post author (and the documentation) should be more detailed at his explanation, and I’m here to make it easy for you!

After install the Rest Client extension for Visual Code, create a folder to store the “rest config files” and open it on Visual Studio Code.

Create the file that we’ll make the rest calls and name it with the extension ‘.rest’ or ‘.http’ (this extensions will enables some cool functions you’ll love).

2017-10-22

1st tip: Always save with .rest or .http extension. It enables color scheme that differentiates the comments, HTTP verbs and the endpoint.

2017-10-22 (1)

If you save as .html file, it’ll work too, but, the color scheme and the call buttons will be gone.

2017-10-22 (2)

2nd tip: use the # character to isolate and name the calls. REST Client extension could recognize any line begins with three or more consecutive # as a delimiter between requests.

In the example below, I clicked ‘Send Request’ at the ~/api/names and got a 404 error. The subsequent requests are not fired.

2017-10-22 (4)

3rd tip: The GET verb is optional and it’ll works if you put it or not, but, if you want to make a POST call, it will be mandatory.

2017-10-22 (5).png

4th tip: Variables can help you to test the calls! Just wrtite @yourvar = something, put the {{yourVar}} in the call and done!

Attention: the three or more consecutive # delimiters isolates the requests, not the variables!

Ex. 01. The document is read from top to bottom and the var ‘theName’ was redefined at the third request, and was passed for the second request.

2017-10-22 (6)

Ex.02. I renamed the var that holds the value “Jimmy London” and call the third request. The value on the request was the value from the second request.

2017-10-22 (7)

When you put the values at the URL, NEVER, EVER put the values in quotes! As the extension follow the RFC 2616, you don’t need to do it.

If you’ll pass the data at the body, use the quotes to avoid errors!

2017-10-22 (8)

With quotes…

2017-10-22 (9)

About the mandatory blank line, if you don’t put a blank line between the header and the body, you’ll get this error.

2017-10-22 (10)

 

Hope you liked this tip! See you on the next post!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s