How to use RapidAPI Client for VS Code to test APIs?

Mon Jul 25 2022

5 min read

Testing your APIs is essential, especially when your application’s whole architecture relies on them. Other use cases exist where you have to look at the response an endpoint brings. You can write additional code, find other methods to check the response or test the endpoints. With RapidAPI Client for VS Code, you can do all this without leaving your code editor.

In this piece, we will look at how you can test your API inside your code editor using the RapidAPI VS Code extension. So without any further ado, let’s jump in!

Loading component...

Testing APIs Using RapidAPI Client For VS Code

We will test two kinds of REST APIs using the extension. The first will be a public REST API from RapidAPI Hub. Whereas, the second will be a REST API serving from a Node.js and Express.js server. We will set up a simple Node.js REST API for this one.

Testing a Public REST API

Let’s look at how you can test a Public REST API using the RapidAPI Client for VS Code.

→ STEP #1

We will use the Famous Quotes API. For this, head over to the RapidAPI Hub and create an account. Then search for Famous Quotes API in the search box.

Select the Famous Quotes API from the search results.

Loading component...

Once you click the button, you will be redirected to another page where different available subscription packages will be shown. Let’s go with the free one for now.

After all this, you will be redirected back to the original page. Here you will have a key x-rapidapi-key. Go ahead and save it somewhere. We will have to send it in the API request header while testing.

→ STEP #2

Go ahead and open VSCode. Now click on the RapidAPI icon present in your VSCode sidebar. Once you click on it, you will see RapidAPI Client Extension View. Click on the plus icon beside the three vertical dots in front of the Requests.

It will create a new request tab where you can look at the API response and test it out.

→ STEP #3

To test the API, we need the following things that are present on RapidAPI’s Famous Quotes API page:

  • HTTP Request Method
  • Famous Quotes API URL
  • Query Parameter Values
  • Header values

So go ahead and copy these values somewhere. Now go back to the request tab of the RapidAPI Client you created in the last step. Select the HTTP method from the dropdown menu. In this case, we will choose the GET method. Now paste the API URL beside the send button in the API input box.

Now click on the Headers tab and add the header values that you copied from the Famous Quotes API page.

Afterward, click on the Query section and add your API query parameters that you copied from Famous Quotes API page.

→ STEP #4

Once everything is done, click on the Send button. It will make an API request and show the results to you. You can look at the response in multiple formats. Let’s go with the JSON Text.

There you have it. You have successfully called and tested a public REST API using the RapidAPI Client.

Loading component...

Testing a Node.js REST API

I have already set up a Node.js server and written a small REST API. If you do not know how to do this, we have written a detailed piece on how you can create a simple Node.js-based REST API.

Now open RapidAPI Client. Ensure that your Node.js is running. Now create a new request tab as you did earlier. Choose the GET method from the dropdown and enter the following URL in the API input box next to the Send button.

​http://localhost:5500/hello

Now click on the Send button. You will see that the API has brought a response that you can look at in different formats. Let’s go with the JSON Text.

Now change the HTTP method from GET to POST in the dropdown and click on the Send button again. It will bring a response that will be displayed on the right side.

Wrap Up

There you have it, folks. I hope now you know how simple and easy it is to use the RapidAPI Client for VS Code to test REST APIs right inside VS Code. We have also written a detailed introduction about RapidAPI Client for VS Code that you can find here.

If you want to learn how to generate API call snippets using RapidAPI Client for VS Code, we have also written a piece about it that you can find here. RapidAPI Client also lets you generate interfaces for your API response, and you can learn more about it here.