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...
In the Matlab command window (or in a script), you can send a request to the NA-ARC web API like:
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:
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.
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: