[Pharo-users] Best Practices for Adapting JSON based APIs
eric.gade at gmail.com
Sun Sep 8 16:30:33 EDT 2019
Several times in the past couple of years I've found myself attempting to
create objects that incorporate/adapt a given APIs specification -- in
other words, building a mini, pharo based SDK for the given API. These are
always JSON based APIs.
I am not sure what the best practices are for doing this and am looking for
some wisdom from this list. I have a few questions:
1. When passing around JSON-based objects for a given API, is it better to
work with Dictionaries or to create (for example) specific objects for
specific kinds of JSON objects in the API -- ie for Stripe, would you just
work with objects that read and parse Dictionaries or implement
Transaction, User, CreditCard objects, etc, etc?
2. If you create objects for each kind of entity rather than using
dictionaries, what do you do in the (rather common) case where the API
specification allows for a lot of malleability in a given JSON object that
gets passed in for a given kind of request? Often times there can be
arbitrary, non-required key-value pairs set by the user for a given
transaction/request/whatever on the JSON object. I'm not sure how this
would translate to Pharo objects, especially if we are creating a
3. Do you create a method per what would be a key in the spec's JSON object?
4. If a given API spec is itself written in JSON, do we have some way of
"automatically" creating the equivalent objects in Pharo (since both are
I am currently considering developing a bare-bones proof of concept package
for making a Matrix Client <https://matrix.org/docs/spec> but I'm a bit
flummoxed about how to proceed, since there seem to be many ways to do this
-- some that might be worse than others for testing, abstraction, etc, etc.
Any advice is much appreciated. Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Pharo-users