How to use the NA-ARC web API from Matlab ?

Using the NA-ARC web API is as simple as reading the outcome of an URL, ie reading the response of an HTTP GET request.

Because Matlab offers you the possibility to do this with the function 'urlread' (see Matlab help for 'urlread'), we paid some time to write the NA-ARC web API so that it can output results readable from Matlab. This is much easier than parsing the JSON or CSV results.

Note 1: At this time, only the NA-ARC web API service 'get' provides functions able to output results in the Matlab format. All service 'get' functions (except 'ticket' and 'ftplist') can be used with the output format restriction 'matlab'.

Note 2:The Matlab format output from the API is not to be confused with the binary Matlab file format .mat ! Here the Matlab format means a chain formated to be used by an 'eval' command, see below...

Example

In the Matlab command window (or in a script), you can send a request to the NA-ARC web API like:

>> urlread('http://www.ifremer.fr/lpo/naarc/api/v1/?get=np&by=year&format=matlab')

ans =

[1997,247;1998,595;1999,634;2000,1717;2001,3704;2002,6700;2003,8106;2004,10096;2005,13736;2006,17878;2007,19906;2008,20254;2009,19701;2010,19765;2011,22237;2012,8233;]

>>

This query output is the number of profile per year. You see that the result is something quite familiar in Matlab and very different from the default output format JSON. So basically, a standard workflow to query the NA-ARC web API would be something like:

>> apiroot = 'http://www.ifremer.fr/lpo/naarc/api/v1/';
>> apiquery = '?get=np&by=year';
>> C = eval(urlread([apiroot apiquery '&format=matlab']))

C =

     1997 247
     1998 595
     1999 634
     2000 1717
     2001 3704
     2002 6700
     2003 8106
     2004 10096
     2005 13736
     2006 17878
     2007 19906
     2008 20254
     2009 19701
     2010 19765
     2011 22237
     2012 8233

>>
>> whos C
Name Size Bytes Class Attributes
C 16x2 256 double
>>

Isn't that pretty cool ? You can use the Matlab 'eval' function to evaluate the NA-ARC web API output returned by 'urlread' and in one line directly store the result in your workspace !

You can now look at the documentation for each functions of the service 'get' to have the detailled description of the output using a matlab format.

Note

If you looked at the documentation for the Matlab function urlread you may have noticed than one way to use the function is:

S = URLREAD('URL','method',PARAMS) passes information to the server as
		    part of the request.  The 'method' can be 'get', or 'post' and PARAMS is a 
		    cell array of param/value pairs.

To request the NA-ARC web API in this case, you must specify the method 'get' which is not to be confused with the API service 'get', here it's the HTTP method, for instance:

>> apiroot = 'http://www.ifremer.fr/lpo/naarc/api/v1/';
>> PARAMS = {'get','np','by','year','format','matlab'};
>> C = eval(urlread(apiroot,'get',PARAMS))