Hurl: Run and test HTTP requests with plain text
hurl.dev
hurl.dev
Hurl runs super fast without startup latency unlike a lot of tools in this category written in node. The plain text format can be checked in and this can be part of your CI process. Hurl can capture data from previous requests to run workflows and serve as a testing tool. The main downside is the lack of a GUI, although I imagine it being not that hard to do something like make a plugin for VSCode that will add a run button to the text file and display the result in the editor.
it is really a problem with JavaScript engines, not Node or with the tools itself
I'd suggest taking a look at bun, which is built with fast startup time in mind: https://bun.sh
instead of:
GET https://example.org/data.tar.gz
HTTP/1.0 200
[Asserts]
sha256 == hex,039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81;
...this? get "https://example.org/data.tar.gz" {
sha = "039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81"
}
Or, having a separate category for asserts: get "https://example.org/data.tar.gz" {
asserts {
sha = "039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81"
status = 200
}
}
Or KDL (https://github.com/kdl-org/kdl): get "https://example.org/data.tar.gz" {
asserts {
sha "039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81"
status 200
}
}Thank you so much for sharing!
It’s not so hard to make this in any language. Just emit output to a text file and have a flag in your test command to overwrite the snapshots instead of asserting that the current output matches the snapshot.
I found that I didn’t even use assertions sometimes. I’d just check git to see if there’s a diff in the snapshots for refactoring
Started investigating how it can be integrated into GitLab CI/CD in the most efficient way.
Simple - install Hurl using before_script every time into the used container image. Example in https://gitlab.com/everyonecancontribute/dev/hurl-playground...
Efficient - build a custom container image (the upstream container image behaves unexpected when overriding the entrypoint for CI/CD, need to investigate and create an issue) Example in https://gitlab.com/everyonecancontribute/dev/hurl-playground...
A quick example to check the website body can be achieved with
$ vim dnsmichi.at.hurl
GET https://dnsmichi.at
HTTP/1.1 200
[Asserts]
body contains "Everything is a DNS problem"
$ hurl --test dnsmichi.at.hurl
While reading the documentation and all its great ways to use assertions on response https://hurl.dev/docs/asserting-response.html and play with regex, and even built-in JSON parsing, I thought of querying the Algolia search API for HN: $ vim hackernews.hurl
GET https://hn.algolia.com/api/v1/search
[QueryStringParams]
query: gitlab
tags: front_page
HTTP/2 200
[Asserts]
jsonpath "$.hits" count > 0
$ hurl --test hackernews.hurl
Not perfect yet, but shows the possibilities and maybe kicks off more ideas.Will add more use cases, upstream PRs, and a blog post soon. https://gitlab.com/everyonecancontribute/dev/hurl-playground
Code example: https://github.com/for-GET/katt/blob/master/doc/example-http...
Disclaimer: I'm one of the authors, thus biased, but the reason I'm mentioning KATT is that the low barrier of entry for captures and asserts makes it a nice requirement tool for non-techs to write complex API scenarios.
- chaining requests,
- passing data from a request to another (with captures or with cookies, each file being its own cookie session),
- gettings resources and checking payload SHAS
- checking responses (JSONPath, XPath on body response, headers etc...)
- retry / polling scenarios (polls until a resource is created for instance)
- comments things (we use Hurl as documentation for APIs workflows)
You can do these things using scripts and curl of course. We appreciate having a tool that works locally on Windows / macOS / Linux and integrates nicely in CI/CD. Hurl uses a (very small) fragment of libcurl. curl is much much powerfull, we love it.
Are cookie jars not sufficient for that? Curl supports those on its own.
- chaining - It's just code so put multiple get calls after one another - captures - Just variables. With sessions you can also get automatic cookie-capture. - Payload - Yes - Parsing responses - stdlib has json and xpath libraries that also can be written as oneliners. Html not always being pure xml is a problem, but can be solved with other libraries, like beautifulsoup. - Retries - a bit more hassle to set up but also doable with relatively small effort. - Comments - yes
What's missing would be benefits given by the declarative nature, such as more human friendly output on jsonpath assertions. But that's often easily extended with functions in the test framework and outweighed by the flexibility given by allowing you to extend the capabilities with more functions or put computations between chained calls or other external inputs/outputs needed in the tests. How often do you really need to test only the http call and nothing else?
1 - When the content of a JSON variable is an XML string, or a JSON string, detect this and format white space for readability.
2 - Support pulling either the entire request or just the body from a file, and looping over all files in a directory.
3 - Pull data out of a response, put it in an environment used by later lines in the script.
0 - https://www.jetbrains.com/help/idea/http-client-in-product-c...
https://github.com/stepci/stepci
Disclaimer: I'm the original author
Show HN: Hurl – Run and test HTTP requests with plain text, curl and Rust - https://news.ycombinator.com/item?id=28758226 - Oct 2021 (49 comments)
-------
Edit: these are apparently not the same thing (thanks to johns for pointing this out):
Show HN: Hurl.it is back – Make HTTP Requests - https://news.ycombinator.com/item?id=27026178 - May 2021 (15 comments)
Show HN: Hurl – Run and test HTTP requests - https://news.ycombinator.com/item?id=25655737 - Jan 2021 (11 comments)
Make HTTP requests from your browser - https://news.ycombinator.com/item?id=3439653 - Jan 2012 (66 comments)
Hurl is back: http://hurl.it/ - https://news.ycombinator.com/item?id=1881945 - Nov 2010 (2 comments)
Hurl - https://news.ycombinator.com/item?id=1311146 - May 2010 (31 comments)
Hurl - https://news.ycombinator.com/item?id=818648 - Sept 2009 (31 comments)
Hurl is not enough for some of the tests I want to write, i.e. testing sending a 50MB file, or dynamic content.
If you're going to do a single request or a few requests in isolation, curl is the way to do.
If you wanna do a full fledged testing suite, might as well using a proper scripting language or a test framework.
Hurl hits the spot between those two for me.
Anyone compared both and have an opinion?
The Gherkin syntax of Karate is a matter of taste, although I prefer more declarative syntax
Agreed on Gherkin vs. declarative, a t depends on who the test is for. I’d probably only use Gherkin for APIs if my product was developer-focused (eg Stripe, Plaid).
GET https://api.foo.net
HTTP/1.1 200
[Asserts]
jsonpath "$.books[0].author.name" == "Hugo"[0] https://www.ayrshare.com/hurl-run-and-test-http-api-requests...
I'm not sure if it can do the sort of web scraping (from the DOM) that Hurl claims to support, though. I guess you can run Hurl in CI, too.
It's a very good way to show folks how to use an API, and I try to check in these files to VCS. You can also write test assertions with it and it also supports environment-based secrets.
There are a lot of similar tools (see this thread https://news.ycombinator.com/item?id=33287137#33296902), we try to focus on: simple plain text format, CI/CD integration, fast multi-platform CLI. Plenty of options