Re:Show HN: SWAPI – A Star Wars API
by idlewan on Friday December 05, 2014 @11:19AM
(#8705235)
Is there a reason you're not using numbers in the json output?
is better represented as:
[ Parent
| on HN ]
I usually do the same thing. Both the 32-bit issue (that issue being with JSON libraries, not the spec) but also: IDs are opaque tokens. If down the road it makes sense to use UUIDs or have a sharding hash or something else, you don't want clients tied to expecting an integer datatype.
I feel like a lot of people will see that an just cast it to an int however.
That could happen but in a lot of strictly typed languages it would be non-obvious and special effort to do so.
There's absolutely no justification to send ints when you have any reasonable chance of needing to change it to a string later. Besides, IDs in a public API fundamentally are not numbers. You don't add them, subtract them, multiply them, shift them, inspect any property of them besides equality, or anything. They're opaque tokens used to identify things with the server.
Re:Show HN: SWAPI – A Star Wars API
by wise_young_man on Friday December 05, 2014 @11:21AM
(#8705247)
What if the integer exceeds the maximum allowed on 32 bit machines and you try to decode the JSON?
Re:Show HN: SWAPI – A Star Wars API
by djtriptych on Friday December 05, 2014 @11:25AM
(#8705268)
That has nothing to do with JSON, which allows numbers of arbitrary size.
Re:Show HN: SWAPI – A Star Wars API
by paulhallett on Friday December 05, 2014 @11:25AM
(#8705269)
This is mostly just a typo in the examples I put, but I will consider using only strings for this type of stuff, to avoid issues.