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:
import requests
# Get the 50 latest sites in MagIC
response = requests.get(
'https://api.earthref.org/v1/MagIC/contribution/16663',
headers={'Accept': 'text/plain'}
)
# Check the response status code
if (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 contribution
print(response.content[0:100])
Or searching with Python:
import requests
import pandas
# Get the 50 latest sites in MagIC
response = requests.get(
'https://api.earthref.org/v1/MagIC/search/sites',
params={'query': 'devonian', 'size': 50},
headers={'Accept': 'application/json'}
)
# Check the response status code
if (response.status_code == 404):
print('Request URL is incorrect.')
# Parse the JSON output into a dictionary
json_response = response.json()
# Retrieve the list of sites, of which each site may have multiple data rows
sites = json_response['results']
# Flatten the sites rows
def flatten(listOflists):
return [item for sublist in listOflists for item in sublist]
sites_rows = flatten(sites)
sites_df = pandas.DataFrame(sites_rows)
sites_df.head()
npm install
npm dev
# API running at http://localhost:3200