Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
eimrek opened this issue Jul 11, 2024 · 0 comments
Open

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

eimrek opened this issue Jul 11, 2024 · 0 comments

Comments

@eimrek
Copy link
Member

eimrek commented Jul 11, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant