The deployed API is currently available at https://api.earthref.org/v1 with documentation at https://api.earthref.org. These GET requests can be made in the browser to test the API:
These requests can also be made with an HTTP request client, for example getting a contribution with Python:
importrequests# Get the 50 latest sites in MagICresponse=requests.get(
'https://api.earthref.org/v1/MagIC/contribution/16663',
headers={'Accept': 'text/plain'}
)
# Check the response status codeif (response.status_code==404):
print('Request URL is incorrect.')
if (response.status_code==204):
print('Contribution ID doesn''t exist.')
# Parse the first 100 characters of the contributionprint(response.content[0:100])Or searching with Python:
importrequestsimportpandas# Get the 50 latest sites in MagICresponse=requests.get(
'https://api.earthref.org/v1/MagIC/search/sites',
params={'query': 'devonian', 'size': 50},
headers={'Accept': 'application/json'}
)
# Check the response status codeif (response.status_code==404):
print('Request URL is incorrect.')
# Parse the JSON output into a dictionaryjson_response=response.json()
# Retrieve the list of sites, of which each site may have multiple data rowssites=json_response['results']
# Flatten the sites rowsdefflatten(listOflists):
return [itemforsublistinlistOflistsforiteminsublist]
sites_rows=flatten(sites)
sites_df=pandas.DataFrame(sites_rows)
sites_df.head()npm install
npm dev
# API running at http://localhost:3100
