Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Multiline GET request using cURL

I want to format a valid GET request in a way it is more human readable. There are many parameters and might be more in the future. So in case of a documentation, how would you format a long URL in a cURL command ? Preferably exhibiting each queryparam in a newline.

curl --header 'header1: XXXXXX' 'https://localhost/api/similar?word=science&target=en&target=fr&target=bg&target=ar&target=fr&source=en&limit=10&score=0.5'

Please note the repeating param target which is valid (and is interpreted as an array depending on the query parser on server side).

Edit: This is what I already tried without success:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

curl -XGET -G 'https://localhost/api/similar?' \
-d word=science \
-d target=en \
-d target=fr \
-d target=bg \
-d target=ar \
-d target=fr \
-d source=en \
-d limit=10 \
-d score=0.5

Unfortunately, this is not working

>Solution :

you’re very close 🙂 just replace -XGET with –get and it should work

curl --get 'https://localhost/api/similar?' \
-d word=science \
-d target=en \
-d target=fr \
-d target=bg

also note that the \ syntax for multi-line shell invocations is specific to posix shells, meaning it won’t work on Microsoft Windows, in Windows’s cmd it would be

curl --get 'https://localhost/api/similar?' ^
-d word=science ^
-d target=en ^
-d target=fr ^
-d target=bg

(and again ^ is exclusive to Windows so that won’t work on posix shells~)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading