←back to thread

460 points flykespice | 1 comments | | HN request time: 0.517s | source
Show context
jicea ◴[] No.44324928[source]
Hi Hurl maintainer here, happy to answer any question and get feedbacks!
replies(7): >>44325286 #>>44325359 #>>44325931 #>>44325991 #>>44326925 #>>44328252 #>>44328285 #
gavinray ◴[] No.44325931[source]
So, myself and many folks I know have taken to writing tests in the form of ".http" files that can be executed by IDE extensions in VS Code/IDEA.

Those basically go in the form

   POST http://localhost:8080/api/foo
   Content-Type: application/json

   { "some": "body" }
And then we have a 1-to-1 mapping of "expected.json" outputs for integration tests.

We use a bespoke bash script to run these .http file with cURL, and then compare the outputs with jq, log success/failure to console, and write "actual.json"

Can I use HURL in a similar way? Essentially an IDE-runnable example HTTP request that references a JSON file as the expected output?

And then run HURL over a directory of these files?

replies(2): >>44327779 #>>44328947 #
xnorswap ◴[] No.44327779[source]
I like this approach.

Is your expected.json the actual response body, or is it an object containing body, status, header values, and time-taken, etc?

replies(1): >>44329257 #
1. gavinray ◴[] No.44329257[source]
It's only the response body, but that's due to not having a usecase to validate headers or status code.

I really like it because it serves 3 purposes:

- API docs/examples that you can interact with

- Test cases

- Manually invoking API endpoints when working on the underlying code, in an iterative loop