FamilySearch / fs-php-lite

Lite PHP SDK for the FamilySearch API
Apache License 2.0
3 stars 4 forks source link

Can we get a better POST method? #1

Closed justincy closed 8 years ago

justincy commented 8 years ago

Here's how to currently POST to a URL with a JSON body:

$fs->post('/some/url', null, null, $data);

The two nulls in the middle bother me. They are the query params and headers variables. Those need to be available for setting on a POST but the user shouldn't have to specify that they won't be setting them.

We can't cant change the order because then it won't match the parameter order of get() and request(). Though we might change the parameter order of request(), we would end up with other situations where we're passing in null (you can pass an empty array too).

A better way to do this is using an options object.

$fs->request('/some/url', [
    'method' => 'POST',
    'body' => $data
]);

$fs->post('/some/url', [
    'body' => $data
]);

Is that much better?

justincy commented 8 years ago

The best characteristic of the proposed change is that the order of parameters doesn't have to be remembered. I have trouble remembering the order even though I decided on it yesterday and have been using it quite a bit since then.