by paradite · 3y ago · 0 comments
I often find myself in a situation when testing API to request for "API request and API response", including header, body, etc, the full complete information. This helps to identify any issue with it, and keep the full record for the future reference (it happens a lot that I need some information on the old API behavior weeks later).
There seems to be lack of a single word in English to describe this except the long phrase above. Anyone has good suggestion?
It goes without saying that this is a hard requirement I have for any API client but sadly most ones I tried always lack some information somewhere.
Rather than a general term, though, what you probably want to focus on — especially because you want to "keep a record" — is the common file format used for these: https://en.wikipedia.org/wiki/HAR_(file_format)
(It was created and initially supported by web browsers, but many CLI/GUI dev tools should be capable of emitting HARs as well, often "off to the side" in some logging directory while also presenting separate, pretty info on stdout.)
For these types of records you typically want to store them in internal documentation system which usually consist of markdown or rich text documents for ease of browsing.
Saving it as an attachment is possible, but it would require whoever that is reading it to download and view it inside a HAR viewer (Chrome), a few extra steps.
If you mean the request and response message pair, we call it "exchange" [0].
> It goes without saying that this is a hard requirement I have for any API client but sadly most ones I tried always lack some information somewhere.
Both HTTPie Desktop and HTTPie CLI allow you to see the entire exchange. In the CLI, you can use the --verbose flag [0]. In the desktop app, there’s a “Request” tab.
They both also support previewing the request without sending it. The CLI has --offline [1], and the Desktop has a live preview feature [2].
[0] https://httpie.io/docs/cli/what-parts-of-the-http-exchange-s...
[1] https://httpie.io/docs/cli/offline-mode
[2] https://raw.githubusercontent.com/httpie/desktop/master/.git...
The desktop app also allows you to copy a corresponding HTTPie CLI command, which you can then enrich with --verbose, run in the terminal, and more easily copy the whole exchange output.
Please do consider adding a feature to export everything in one shot. It would save people like me a lot of clicks (for a lot of APIs across different environments).
But writing tests in markdown is not for everyone. Here are few examples of what "test files" look like https://github.com/apiaryio/api-blueprint/tree/master/exampl...
I didn't use in for two years so I can't say how well it works today (it doesn't appear to be actively maintained).
If the result doesn’t match what’s in the file, the test fails. You can run the tests with a special flag to update them in place.
It gives great regression coverage on that edge of the system and it can easily be done with a good language HTTP library.