curl-library
Re: a URL API ?
Date: Thu, 2 Aug 2018 13:41:34 -0400
On Thu, Aug 2, 2018 at 11:36 AM, Daniel Stenberg <daniel_at_haxx.se> wrote:
> On Thu, 2 Aug 2018, Geoff Beier wrote:
>
> The setters would be important to us. I might be bikeshedding here, but
>> the ability to add to the query would be very nice. So something like
>> curl_url_query_append(urlp, "numitems", 3)
>>
>
> That ("numitems", 3) approach is very specific for adding a
> "[name]=[number]" snippet though. Shouldn't it rather be a function for
> appdending a generic string?
>
> curl_url_query_append(urp, "numitems=3");
>
> ... or using the alternative B API (https://github.com/curl/curl/
> wiki/URL-API#url-api-alternative-b) approach:
>
> curl_url_append(urp, CURLUPART_QUERY, "numitems=3");
I was actually contemplating an API that would append key-value pairs and
just do the right thing based on type. So overloads like:
curl_url_append(urp, <string type>, <numeric type>);
curl_url_append(urp, <string type>, <string type>);
curl_url_append(urp, <string type>, <buffer type>, <length type>);
would take care of encoding key=value appropriately as opposed to a
function like
curl_url_query_append(urp, "numitems=3");
that would assume the caller has encoded it appropriately and just wants to
append it to a query string.
Like I said, I recognize that this might all be bikeshedding and think
what's been proposed is an excellent addition to the current API. But based
on where I've tripped or seen people trip, I think something like this
would match the mental model of a web api user well and cut down on a
common avenue for misuse without adding much complexity to the library.
Geoff
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2018-08-02