Developers use a lot of URLs: your app’s URLs, URLs for consumed services, etc. These URLs, and sometimes their payloads may differ per environment. And as a dev you’re going to constantly hit them. Developers have relied on utilities outside the IDE to track the URLs, send test payloads to the URLs, and inspect the response. Now you can do all of that from your IDE! To do this we’ll use the REST Client extension for Visual Studio Code.
### First Test
GET http://microsoft.com HTTP/1.1
As soon as you save, you’ll see a Send Request button appear right after the ###.
Click send request and you’ll see the response right in the IDE.
That’s it! No need to open a web browser, debug tools, networking, and then inspect responses- it’s all right there!
If you want to share the response - you can save, copy/paste, or explore the response at your leisure!
Want to share everything you’ve done so far? Simply add the client.rest file to source control and anyone who opens it will run the same call as you just did. But, of course, we’re just getting started!
We can add as many URLs to this file, or we can create other files with a .rest extension. For now let’s add to our existing file. Multiple calls are separated by a new line starting with ###
Add a post request by adding a ### to the bottom of the file.. Just add ### to add additional requests.
As you’d expect you can use <ctrl>+ space to autocomplete all entries.
###
POST https://localhost:5001/api/Patient HTTP 1.1
Content-Type: application/json
{
"name":"H. Simpson"
}
Click Send Request and you’ll get a response. You can imagine having a file called services.rest that describes the payload and urls for each of your dependent services, and another file called app.rest that describes the URLs and payloads for your app’s URLs! But if we have many URLs we might want to change the host depending on the environment.
You can add variables in the same client.rest file using the syntax
@<variable name> = <variable value>
Then you can place the variable by using {{variable name}} anywhere in the rest of the file.
If you want the variable to refer to a specific request simply put the variable declaration inside the ###.
You can also store variables at the environment level (esp. useful if you want to avoid checking in secrets to source control).
@host=microsoft.com
### Get Base
GET https://{{host}}
### Post Base
@patientid=1234
POST https://localhost:5001/api/Patient/
Content-type: application/json
{
Id:{{patientid}}
}
This is great for development but it makes developing against FHIR endpoints incredibly easy.
Take a look at this example
### Get single patient
@patientid=f5e7ee94-bfc6-465e-a64d-f0c90e3d50f5
GET https://{{fhirname}}.azurehealthcareapis.com/Patient/{{patientid}}
Authorization: Bearer {{auth.response.body.access_token}}
This gets a single patient resource. Why is this better than a Postman collection? You can easily check it into source, you can easily edit it without having to click around the Postman GUI, and most importantly- you can quickly copy paste the request or response since it’s all text.
Please see the example client.rest included in the Open Hack for FHIR.
This example includes queries for getting a token, fetching a patient, and fetching a list of patients!
Using the REST Client has many benefits. But chief among them is speed. If you use an external tool, you’ll have to alt-tab to it while you develop. You’ll have to be trained, and train others on it. With REST Client- you only need to know how to use the same IDE you already know and love!
Postman still has features that you won’t find anywhere else, but for most day-to-day app dev use cases you’ll find REST client extension in Visual Studio Code meets your needs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.