Orange-OpenSource / hurl

Hurl, run and test HTTP requests with plain text.
https://hurl.dev
Apache License 2.0
12.27k stars 476 forks source link

Insert a JSON body from another file, instead of putting the full JSON in the hurl file? #3010

Closed timotk closed 3 days ago

timotk commented 3 days ago

First of all: I'm not sure if it is a feature request or I am doing something wrong!

Problem to solve

I have a very large JSON file, which includes some binary images. This data is quite large and would make the hurl file unreadable.

I have tried passing the body as a variable argument, as follows:

POST http://localhost:8000/
```
{{ body }}
```
HTTP 200

Then run it with: hurl request.hurl --variable body='{}'

This works fine for simple JSON, but I can't get it to work with reading the JSON from a file.

I can imagine an option where we specify the file in the hurl file:

POST http://localhost:8000/
```
{{ file data.json }}
```
HTTP 200

Related issues

https://github.com/Orange-OpenSource/hurl/issues/2145 https://github.com/Orange-OpenSource/hurl/issues/2258

Proposal

Have a simple way of reading the request body from another file (see above).

jcamiel commented 3 days ago

Hi @timotk

I think you're looking for file body request:

POST https://example.org
file,data.bin;
HTTP 200

If you're sending JSON data, you can add Content-Type request header:

POST https://example.org
Content-Type: application/json
file,data.bin;
HTTP 200

You can see it also in the samples documentation

We'll also support, in the future the syntax you wanted to use

POST http://localhost:8000/
```
{{ file data.json }}
```
HTTP 200
timotk commented 3 days ago

Hi @jcamiel, that's it, thanks a lot! Not sure how I missed that 🤷‍♂️

jcamiel commented 3 days ago

Documentation can always be improved though, don't hesitate to propose improvements!