An easy way to reuse requests #274
Replies: 3 comments
-
|
This could indeed be very useful. For the time-being, we have generated Hurl files for reuse. |
Beta Was this translation helpful? Give feedback.
-
|
@spaceaardvark I've transformed this discussion to an issue #317 as we're going to only use issues |
Beta Was this translation helpful? Give feedback.
-
|
Request reuse in Hurl is the most-requested missing feature — here are the approaches that work today and what a native solution might look like: Current workaround: templated files: #!/bin/bash
# Use shell variables + envsubst
export AUTH_TOKEN=$(hurl --variables-file secrets.env auth.hurl | jq -r '.token')
# Then in other .hurl files, reference via variable
BASE_URL=https://api.example.com hurl --variable AUTH_TOKEN=$AUTH_TOKEN main.hurlCurrent workaround: shell scripting + file composition: # auth.hurl — just the auth request
POST https://{{base_url}}/auth
Content-Type: application/json
{"username": "{{user}}", "password": "{{pass}}"}
HTTP 200
[Captures]
token: jsonpath "$.token"
# api_call.hurl — uses captured token from auth.hurl
GET https://{{base_url}}/resource
Authorization: Bearer {{token}}
HTTP 200# Run them in sequence, sharing captures
hurl auth.hurl api_call.hurl --variables-file .envHurl already chains requests in a single file and passes captures between them — the gap is that you can't define a "reusable request block" that can be included elsewhere. What a native solution would look like: # Hypothetical: import syntax
import auth from ./auth.hurl
GET https://api.example.com/data
Authorization: Bearer {{auth.token}}The |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I don't think there's a way to do this yet, but it would be great to have an easy way to reuse a request in multiple
.hurlfiles.For example, suppose
sign-in.hurlsigns in a test user in and extracts their name and email from the response. I would like to reuse that request intest-1.hurlandtest-2.hurlwithout having two duplicate everything insign-in.hurl.Beta Was this translation helpful? Give feedback.
All reactions