cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: A small nudge to fix a frequent -X misuse?

From: Alex Bligh <alex_at_alex.org.uk>
Date: Sun, 30 Aug 2015 19:14:29 +0100

On 30 Aug 2015, at 17:36, Daniel Stenberg <daniel_at_haxx.se> wrote:

>>
>> Given that, if I'm documenting a REST call in curl, I'll *always* specify -XGET or -X POST (or whatever), so it's clear,
>
> Then you're one of the persons I want to change! =)
>
> I don't think it is clear. I think it actually makes a disservice to the users reading that. First, I think it misleads the user into believing he or she needs to use -X when using curl to do these operaitons and secondly, it misleads the user into believing that the -X method is actually what tells curl how to act.

Yup, and I don't want to be changed :-) Just to be clear, I'm autogenerating all this and don't want 'the best' curl command line, but the most readable (for whoever is translating it to their REST tool du jour).

> Like they may then wrongly believe that curl would act differently if you did -XPOST or -XGET, when in fact curl doesn't care about what -X is set to, but it is the other option(s) that control how it behaves.

Really? I'm feeling slightly sensitive about this as it took me a little while yesterday to work out why my otherwise working script failed when I added a '-d' component - I'd not explicitly set '-X GET' but relied on it being the default. I thought in such a circumstance (presence of -d), '-X GET' did explicitly change the HTTP action from POST to GET.

Bottom of the (working) script looks like this:

# Run curl to call the endpoint, passing the output through json_pp merely to
# make it pretty.
set -x
curl -s -X GET -u "${JOB_ADMIN_USER}/${JOB_ADMIN_UUID}:${JOB_ADMIN_PASSWORD}" "${ENDPOINT}${API_CALL}" -d "measureKeys=${MEASURE_KEYS}" -d "resourceUUID=${RESOURCE_UUID_ARRAY}" | ${JSON_PP}

Removing '-X GET' breaks it, as it uses 'POST' instead of 'GET'.

Obviously under your proposal in the above circumstance it won't produce the warning anyway. However, anyone reading that example and an example without '-d' will have to understand how curl changes the HTTP action depending on presence of '-d'.

-- 
Alex Bligh
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ:        http://curl.haxx.se/docs/faq.html
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2015-08-30