Most "pythonic" syntax to use for an API client library

DL Neil PythonList at DancesWithMice.info
Sun Apr 28 23:34:57 EDT 2019


On 29/04/19 6:58 AM, Jonathan Leroy - Inikup via Python-list wrote:
> 1/
> api.customers_list()
> api.customers_info(1)
> api.customers_update(1, name='Bob')
> api.customers_delete(1)

Dislike this because it mixes point and underscore - easy to mistake!


> 2/
> api.customers.list()
> api.customers.info(1)
> api.customers.update(1, name='Bob')
> api.customers.delete(1)

Prefer this because it 'fits' with module/class notations.


> 3/
> api.customers.list()
> api.customers(1).info()
> api.customers(1).update(name='Bob')
> api.customers(1).delete()

Hate this because it identifies the subject (customers), then requires 
customerID (I presume), then states the action, finally we add any 
adverb(s). In some respects, preference for grouping the two (most) 
variable-items.


> ...any other?

Well, seeing you ask: a more HTTP-ish approach *might* be:

api.update.customer( 1, name='Bob' )

ie
api.verb.subject( adjectives and adverbs )

Thus:
api_label/intro/ID.what_we're_going_to_do.who/what_we'll_do_it_to( 
customerID, support_data)

Yet, it doesn't really *look right* does it?
(and someone might complain about mixing the 'different' variable-values...)


Doesn't the framework you are using have its own preference?
-- 
Regards =dn



More information about the Python-list mailing list