-
Notifications
You must be signed in to change notification settings - Fork 21
Description
What it is good for
I have taken the vscode testing script file api.http and adapted it to a script for the HTTP Client, which is a free plugin for IDEs from Jetbrains.
It features (grand word, isn't it)
- distinct environments (local
dev, remoteshuttle) - asserting reponses' status codes
- tracking of
film_idof a newly created film
Where to find the script
There are two files needed. You can find both of them in this gist: https://gist.github.com/bronsen/509f5087b2b463d0268750bd6f236d87
Please make use of them! π
Where you could put the script
I have put them in api/lib/tests, alongside health.rs. However, you can put them whereever you like, as long as you keep those two files (rest-api.http, http-client.env.json) together.
How to use the script
- Open
rest-api.httpin your Jetbrains IDE where you have installed the HTTP Client plugin. - At the top of the file tab, select the appropriate environment from
Run with: - Click the green double arrow
- Observe the results
How the script works
Just like the original api.http file, it's a bunch of http calls (GET, POST, etc) seperated by markers (###). There are placeholders (for example {{host}}), that are filled from the corresponding env file.
GET {{host}}/health HTTP/1.1
HTTP Client also has so-called Response handlers, which are javascript and can access the response object of the previous call, and can also set variables. One such variable is film_id that is used to fill the {{film_id}} placeholder.
#shortened example
POST {{host}}/v1/films
{"some": "data"}
> {%
client.global.set("film_id", response.body["id"]);
# from now on we can use {{film_id}} in the script
%}
I hope this is useful to others, who follow that exhaustive tutorial π ππΎ