bartervg / barter.vg

Track and hold discussion on Barter.vg bugs, enhancements, and other issues
https://barter.vg
MIT License
20 stars 4 forks source link

API: profiles that have not sent or received offers return an array of 1 object #257

Closed antigravities closed 3 years ago

antigravities commented 3 years ago

Describe the bug

Profiles that have not sent or received offers return an array of an object through the API endpoint /u/hexID/o/json, as opposed to an object with with just a key 0. This edge case causes potential issues with parsing the response from endpoint as the returned objects are fundamentally different.

Here is a profile that contains zero offers (at time of writing), as opposed to a profile that contains one or more offers.

Expected behavior

The API should return an an object with with a key 0 if the profile has not sent or received any offers.

Revadike commented 3 years ago

I think the 0-key object is annoying to deal with. I'd rather just remove it.

bartervg commented 3 years ago

The API should return an an object with with a key 0 if the profile has not sent or received any offers.

Researching...

image

Knowledge Acquired https://stackoverflow.com/questions/15290811/php-json-encode-issue-with-array-0-key

$result = json_encode($array, JSON_FORCE_OBJECT);

Result https://barter.vg/u/6f75/o/json

{"0":{"count":0}}
bartervg commented 3 years ago

I think the 0-key object is annoying to deal with. I'd rather just remove it.

Yes, in hindsight, this decision doesn't make much sense. I'll remember it for JSON feed 2.0.

antigravities commented 3 years ago

I think the 0-key object is annoying to deal with. I'd rather just remove it.

I was just aiming for consistency. Breaking changes should be part of a 2.0.