This is an automated email from the ASF dual-hosted git repository.

ako pushed a commit to branch ageviewer_go
in repository https://gitbox.apache.org/repos/asf/age.git


The following commit(s) were added to refs/heads/ageviewer_go by this push:
     new 648c6263 [AgeViewer-Go] Backend-API functions. (#794)
648c6263 is described below

commit 648c62632473470588653b4680c53048f16d192b
Author: Kamlesh Kumar <[email protected]>
AuthorDate: Tue Apr 11 03:42:48 2023 +0500

    [AgeViewer-Go] Backend-API functions. (#794)
    
    * API functions add which needs to be called from frontend to access the 
backend
    
    * API functions add which needs to be called from frontend to access the 
backend
---
 backend/APIfunctions.js | 134 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 134 insertions(+)

diff --git a/backend/APIfunctions.js b/backend/APIfunctions.js
new file mode 100644
index 00000000..6603887c
--- /dev/null
+++ b/backend/APIfunctions.js
@@ -0,0 +1,134 @@
+// some pre-requisites to run these functions on desktop enviroment
+// const fetch = require("node-fetch");
+// const readline = require("readline");
+
+
+// const rl = readline.createInterface({
+//     input: process.stdin,
+//     output: process.stdout
+//   });
+
+// Test data which will come from the frontend
+const conn = {
+  port: "5432",
+  host: "localhost",
+  password: "ABCDEFGH",
+  user: "kamleshk",
+  dbname: "testdb",
+  ssl: "disable",
+  graph_init: true,
+  version: 11,
+};
+
+// cookies will be stored here, these are store whenever connect() fun is 
called 
+// and will be used in subsequent calls
+let cookies;
+
+function connect() {
+  fetch('http://localhost:8080/connect', {
+    method: 'POST',
+    headers: {
+      'Content-Type': 'application/json',
+    },
+    body: JSON.stringify(conn),
+  })
+  .then(response => {
+    console.log(response.status);
+
+    // Store the cookies from the response
+    cookies = response.headers.raw()['set-cookie'];
+
+    return response.json();
+  })
+  .then(data => {
+    console.log(data);
+  })
+  .catch(error => {
+    console.error(error);
+  });
+}
+
+function queryMetadata() {
+  const graph = {
+    name: "demo_graph",
+  };
+
+  fetch('http://localhost:8080/query/metadata', {
+    method: 'POST',
+    headers: {
+      'Content-Type': 'application/json',
+      'Cookie': cookies.join('; '),
+    },
+    body: JSON.stringify(graph),
+  })
+  .then(response => {
+    console.log(response.status);
+
+    return response.json();
+  })
+  .then(data => {
+    console.log(data);
+  })
+  .catch(error => {
+    console.error(error);
+  });
+}
+
+function query() {
+  const payload = {
+    query: "SELECT * FROM cypher('demo_graph', $$ MATCH (v) RETURN v $$) as (v 
agtype);",
+  };
+
+  fetch('http://localhost:8080/query', {
+    method: 'POST',
+    headers: {
+      'Content-Type': 'application/json',
+      'Cookie': cookies.join('; '),
+    },
+    body: JSON.stringify(payload),
+  })
+  .then(response => {
+    console.log(response.status);
+
+    return response.json();
+  })
+  .then(data => {
+    console.log(data);
+  })
+  .catch(error => {
+    console.error(error);
+  });
+}
+
+
+
+
+// dummy function to test the above functions
+
+// let choice;
+// function chooseFunction() {  
+
+// rl.question('Enter the function number: ', (input) => {
+//     const choice = parseInt(input);
+//     if (Number.isNaN(choice) || choice < 1 || choice > 3) {
+//       console.log('Invalid choice. Please try again.');
+//     } else {
+//       switch (choice) {
+//         case 1:
+//           connect();
+//           break;
+//         case 2:
+//           queryMetadata();
+//           break;
+//         case 3:
+//           query();
+//           break;
+//       }
+//     }
+//     // rl.close();
+//     chooseFunction()
+//   });
+
+// }
+
+// chooseFunction();

Reply via email to