web services - Designing a Data-Driven JSON API -
i'm working on api accepts large batch of data , performs few different kinds of analysis on data. rather forcing clients pass in data once each sort of analysis wish perform, thought make sense offer 1 api call , have call accept data , list of actions (i.e., analysis types) perform. (this means api isn't restful, right?) i'll lose clarity of function way, gains in processing time make that.
my question how requests should formatted in json. if client needed post array of data elements , array of actions perform, formatting easy. unfortunately, few of analysis types have options need set. see few ways forward.
separate actions , options items:
{ 'data': [{'id': 1, 'content': 'blah'}, {'id': 2, 'content': 'blah}], 'actions': ['analysis_a', 'analysis_b', 'analysis_c'], 'options': {'option_c': 'blah'} }here it's documentation note
option_cneeds set ifanalysis_cenabled.separate actions , options items, options explicitly tied action:
{ 'data': [{'id': 1, 'content': 'blah'}, {'id': 2, 'content': 'blah}], 'actions': ['analysis_a', 'analysis_b', 'analysis_c'], 'options': {'analysis_c': {'option_c': 'blah'}} }single actions/options item, item acting both list , dictionary:
{ 'data': [{'id': 1, 'content': 'blah'}, {'id': 2, 'content': 'blah}], 'actions': {'analysis_a': {}, 'analysis_b': {}, 'analysis_c': {'option_c': 'blah'}} }single actions/options item bit more data structure clarity:
{ 'data': [{'id': 1, 'content': 'blah'}, {'id': 2, 'content': 'blah}], 'actions': [ {'action': 'analysis_a'}, {'action': 'analysis_b'}, {'action': 'analysis_c', 'options': {'option_c': 'blah'}} ] }
option #1 least favorite, in near future few of our analysis types require same option set (necessarily same value), , situation little easier handle option #1.
i'm pretty torn, thoughts or suggestions appreciated. thanks!
i appreciate option #3 , option #4, because each action self contained, offers more clarity.
whether choosing option #3 or option #4 depends on how perform action, if server have operation retrieve specific action action list name. option #3 might better(because option #4 requires iterate array), if not, think option #4 better.
Comments
Post a Comment