aiidateam / aiida-explorer

A React component to explore AiiDA provenance
https://aiidateam.github.io/aiida-explorer/
MIT License
4 stars 1 forks source link

A single module/file for all the REST API calls #2

Open eimrek opened 3 months ago

eimrek commented 3 months ago

For the REST API calls, a single module would be great, that contains all the functions that are used to call the rest api. The functions should take a baseUrl or apiUrl argument and any other custom arguments.

E.g.

async function fetchNodesPaginated(
  apiUrl,
  fullType,
  page,
  entriesPerPage = 20
) {
  let url = `${apiUrl}/nodes/page/${page}`;
  // query parameters:
  url += `?perpage=${entriesPerPage}&full_type="${fullType}"&orderby=-ctime`;
  if (fullType.includes("process")) {
    url += "&attributes=true";
    url +=
      "&attributes_filter=process_label,process_state,exit_status,exit_message,process_status,exception";
  }
  const response = await fetch(url);
  const result = await response.json();

  return result.data.nodes;
}

Note: error handling should probably be also included. And the output data format should be documented.

This will allow to easily migrate to the new REST API in the future.