[HN Gopher] Hurl: Run and test HTTP requests with plain text ___________________________________________________________________ Hurl: Run and test HTTP requests with plain text Author : delduca Score : 91 points Date : 2022-11-25 16:40 UTC (6 hours ago) (HTM) web link (hurl.dev) (TXT) w3m dump (hurl.dev) | theptip wrote: | I recently found a BDD style tool that has native HTTP | comprehension, which seems like it hits a similar area in the | testing concept space: | | https://github.com/karatelabs/karate | account-5 wrote: | When would you use this over just curl? Genuine question. I like | plain text where I can use it, but don't understand the benefit | of this over curl. | jicea wrote: | My two cents (as a developer of Hurl): | | - 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. | account-5 wrote: | Thanks for the quick reply. I've used curl on windows before | calling it from AHK for quick dirty one off scripts. Hurl | could replace that with the ability to chain requests. | Thanks. | justonemore3 wrote: | Can't this not be easily done using curl | xargs | jq + bash | chained as often as you like | jicea wrote: | Emulating an HTTP session (with cookies passing) between | request is more complicated for instance. Retry based on | response content is doable but easier with a declarative | format. jq is perfect for JSON response, what about | HTML/XML response? Our testers prefer to write a text based | declarative test, instead of a Bash script. It depends on | your needs/backgrounds. | andrewfromx wrote: | Written in rust, lets you define a series of http urls to hit and | assert info about what's returned. i.e. a count of items in a | json array, or a string value of one specific json string. | [deleted] | dang wrote: | Related: | | _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) | johns wrote: | Hurl.it is not the same. All the posts from before Oct. 2021 | are a different thing. | dang wrote: | Oops! Thanks! I've edited the GP to make that clear. | mstade wrote: | Not two days ago I had the thought that it'd be so nice if I | could write tests that were just plain text HTTP requests, and | that the assertions would be just be comparing the responses to | stored plain text HTTP responses, kind of like how snapshot | assertions works in the React world. From a cursory glance this | looks even better than what I had in mind, can't wait to give it | a spin. | | Thank you so much for sharing! | prhrb wrote: | Very useful | ccakes wrote: | Not as usable for testing, but verb.el[1] is a great tool for | doing something very similar in org-mode | | [1] https://github.com/federicotdn/verb | gregwebs wrote: | A better url might be https://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. | dang wrote: | Ok, we've changed to that from https://github.com/Orange- | OpenSource/hurl. Thanks! | xemoka wrote: | re:VSCode; There pretty much already is one, looks fairly | similar formatting too: | https://marketplace.visualstudio.com/items?itemName=humao.re... | ploppyploppy wrote: | Love this tool. Was very useful at a previous place and its Rust | APIs were easy to extend | guilhas wrote: | Some how I did small test and liked httpyac better, for being | able to import requests from other files | | https://httpyac.github.io | | Anyone compared both and have an opinion? | ilyt wrote: | IntelliJ have that feature builtin IIRC | lol768 wrote: | Yeah, this was my initial thought. It reminded me of its REST | API format, which supports post-response scripts (written in | JS) to e.g. set a variable up for an access token after an | OAuth exchange. Hurl's post-response handling seems a bit | limited in comparison. | | 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. | jicea wrote: | Hi I'm one of the maintainer of Hurl! You can capture data | from the DOM using XPath and inject it in next requests | (classic example being a CSRF token for instance). One thing | to have in mind is that Hurl is working on the HTTP level, | there is no JavaScript engine, you get what the network gives | you, like curl. | | 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 | hankchinaski wrote: | Nice tool. I'm just wary of learning custom syntax. Maybe could | use the same primitive of existing unix tools and make the whole | a lot more orthogonal and frictionless. Jq syntax for parsing | json, awk for text | javajosh wrote: | You can get a worse version of this functionality out of | IntelliJ's http client[0]. Hurl seems better for several reasons, | although I wish there was an example showing a few more useful | tricks: | | 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... | smartmic wrote: | I recently switch from custom Bash wrappers around curl to | restclient.el [1]. It has similar features. Especially nice is | the integration with jq for fetching specific data (or inspection | of results with jq-mode). And, whoever is inclined to appreciate | it, the fact that I can stay within Emacs. No need to get | familiar with a new UI/UX. | | [1]: https://github.com/pashky/restclient.el ___________________________________________________________________ (page generated 2022-11-25 23:00 UTC)