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

How to reuse captured bytes of previous response as multipart/form-data field in next request #3752

Open
linkdd opened this issue Feb 18, 2025 · 2 comments

Comments

@linkdd
Copy link
Contributor

linkdd commented Feb 18, 2025

Context

I am currently working on FlowG's backup feature (sorry for self-promotion). The End-To-End test suite of the API is written with Hurl (loves it by the way, thanks for the great work).

I'm trying to implement the backup&restore test. The idea is to send the API request for backup-ing, capturing the response body (which is the actual backup bundled in a binary file) as bytes, and then reuse the captured bytes as part of the "restore" API request.

I'm unsure if I'm misreading the docs, or if they are lacking, or if the feature simply does not exist.

Test case

I tried the following:

GET http://localhost:5080/api/v1/backup/logs
Authorization: Bearer pat:{{admin_token}}
HTTP 200
[Captures]
logs_backup: bytes

POST http://localhost:5080/api/v1/restore/logs
Authorization: Bearer pat:{{admin_token}}
[Multipart]
backup: {{logs_backup}}
HTTP 200

And:

GET http://localhost:5080/api/v1/backup/logs
Authorization: Bearer pat:{{admin_token}}
HTTP 200
[Captures]
logs_backup: bytes

POST http://localhost:5080/api/v1/restore/logs
Authorization: Bearer pat:{{admin_token}}
Content-Type: multipart/form-data; boundary=----test
```
----test
Content-Disposition: form-data; name="backup"; filename="logs.db"
Content-Type: application/octet-stream

{{logs_backup}}
----test
```
HTTP 200

But in both cases, I get the following error:

error: Unrenderable expression
  --> spec/backup.hurl:22:11
   |
   | POST http://localhost:5080/api/v1/restore/logs
   | ...
22 | backup: {{logs_backup}}
   |           ^^^^^^^^^^^ expression with value hex, <big hex value omitted>; can not be rendered

Execution context

  • Hurl Version (hurl --version):
hurl 6.0.0 (unknown) libcurl/8.12.1-DEV OpenSSL/3.0.13 zlib/1.3
Features (libcurl):  alt-svc AsynchDNS HSTS IPv6 libz SSL UnixSockets
Features (built-in): brotli
@linkdd
Copy link
Contributor Author

linkdd commented Feb 19, 2025

I managed to get it working using:

GET http://localhost:5080/api/v1/backup/logs
Authorization: Bearer pat:{{admin_token}}
[Options]
output: backup/logs.db
HTTP 200

POST http://localhost:5080/api/v1/restore/logs
Authorization: Bearer pat:{{admin_token}}
[Multipart]
backup: file,backup/logs.db;
HTTP 200

Though, it would be nice if I could avoid using a file.

@jcamiel
Copy link
Collaborator

jcamiel commented Feb 19, 2025

Hi @linkdd that's exactly what I was going to suggest to you 🤣.

We keep this issue open and we're trying to improve this use-case without creating a temp file.

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

2 participants