Making HTTP calls from inside Rider

I test my code with API calls all the time. Because of this, Rider HTTP Client is a lifesaver.
Usually, I call some endpoint for a token and then try to get some data from the service. So let's try to use Rider for this case.

First, we have to run the client. We can do it from the tools menu.

rider_http_client.png After that, it will pop up with an example request. Let's first get a token from the service that we can use in subsequent calls. You can do it like so:

POST https://reqres.in/api/register
Content-Type: application/json

{
  "email": "eve.holt@reqres.in",
  "password": "pistol"
}

> {% client.global.set("access_token", response.body.token); %}

This call will send a POST request to reqres.in and save the token in a global variable called access_token.

Now let's get some data:

GET https://reqres.in/api/users/2
Authorization: Bearer {{access_token}}
Accept: application/json

And that's all. We can call our services without getting out of the IDE.
Simple, isn't it?

What's more, you can check a file with requests into your repository to always have them within reach.

No Comments Yet