Self-referencing REST API

2 posts / 0 new
Last post
neilcaithness
Self-referencing REST API

I've always thought that REST APIs should include a standard call that returns a definitive list of all currently supported calls. That way one can write consuming software that is self-updating and self documenting.

I've pulled all the calls from the IG Labs web site. Just the call strings for now, though the table also has methods, versions and description fields that could just as easily be pulled.

This is a brittle approach though. I would like to suggest that IG include a call that returns some well formatted json output that is a stable and definitive representation of the current API.

Below is some short Matlab code that does an OK job.

% Get the list of queries from the API documentation
str = urlread('https://labs.ig.com/rest-trading-api-reference');
pat = '<a href="/rest-trading-api-reference/service-detail\?id=\d*">([^<])*';
qcell = regexp(str,pat,'tokens');
% Some Matlab conversion stuff that makes the whole thing look obtuse.
for i = 1:numel(qcell), qstr(i) = qcell{i}; end

qstr'

ans =

'/accounts'
'/history/activity/{fromDate}/{toDate}'
'/history/activity/{lastPeriod}'
'/history/transactions/{transactionType}/{fromDate}/{toDate}'
'/history/transactions/{transactionType}/{lastPeriod}'
'/confirms/{dealReference}'
'/positions'
'/positions/{dealId}'
'/positions/otc'
'/positions/otc/{dealId}'
'/positions/sprintmarkets'
'/workingorders'
'/workingorders/otc'
'/workingorders/otc/{dealId}'
'/marketnavigation'
'/marketnavigation/{nodeId}'
'/markets/{epic}'
'/markets?epics={epicsList}'
'/markets?searchTerm={searchTerm}'
'/prices/{epic}/{resolution}/{numPoints}'
'/prices/{epic}/{resolution}/{startDate}/{endDate}'
'/prices/{epic}/{resolution}?startdate={startdate}&amp;enddate={enddate}'
'/watchlists'
'/watchlists/{watchlistId}'
'/watchlists/{watchlistId}/{epic}'
'/clientsentiment/{marketId}'
'/clientsentiment/related/{marketId}'
'/session'
'/session/encryptionKey'
'/operations/application'
'/operations/application/disable'

Chris
Self-referencing REST API

Hi Neilcaithness,

Thanks for posting this, it's very useful. We've also added this to our list of potential future developments as well!

Cheers,
Chris

Log in or register to post comments