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:
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
CodePudding user response:
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~)