Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for users of Jetbrains IDEs: a HTTP Client script corresponding to api.http #11

Open
bronsen opened this issue Jul 9, 2023 · 0 comments

Comments

@bronsen
Copy link

bronsen commented Jul 9, 2023

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, remote shuttle)
  • asserting reponses' status codes
  • tracking of film_id of 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

  1. Open rest-api.http in your Jetbrains IDE where you have installed the HTTP Client plugin.
  2. At the top of the file tab, select the appropriate environment from Run with:
  3. Click the green double arrow
  4. 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 😅 👍🏾


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant