generated from isommie-web3-projects/polybase_basic_template_js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallSchemas.js
202 lines (160 loc) · 4.79 KB
/
callSchemas.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
const axios = require("axios");
// List all your API endpoints here
const apiEndpoints = [
// GET request to fetch data from the database
{
method: "GET",
endpoint: "/api/schemas/reccoinTestSchema",
},
// POST request to store new data in the database
{
method: "POST",
endpoint: "/api/schemas/reccoinTestSchema",
data: async () => {
// Retrieve form data
const name = document.getElementById("name").value;
const email = document.getElementById("email").value;
const walletAddress = document.getElementById("walletAddress").value;
const verification = document.getElementById("verification").checked;
// Return form data
return {
name,
email,
walletAddress,
verification,
};
},
},
// PUT request to update existing data in the database
{
method: "PUT",
endpoint: "/api/schemas/reccoinTestSchema",
data: async () => {
// Retrieve form data
const name = document.getElementById("name").value;
const email = document.getElementById("email").value;
const walletAddress = document.getElementById("walletAddress").value;
const verification = document.getElementById("verification").checked;
// Return form data
return {
name,
email,
walletAddress,
verification,
};
},
},
// DELETE request to delete data from the database
{
method: "DELETE",
endpoint: "/api/schemas/reccoinTestSchema",
data: async () => {
// Retrieve form data
const id = document.getElementById("id").value;
// Return form data
return {
id,
};
},
},
// Add more endpoints as needed
];
async function callSchemas() {
try {
for (const endpoint of apiEndpoints) {
const { method, endpoint: apiEndpoint, data } = endpoint;
const config = { method, url: `http://localhost:3000${apiEndpoint}` };
if (data) {
config.data = await data(); // Call the data function to get the form data
}
const response = await axios(config);
console.log(`API called: ${apiEndpoint}`);
console.log(response.data); // Output or process the response data as needed
}
} catch (error) {
console.error("Error calling APIs:", error);
}
}
callSchemas();
// const axios = require("axios");
// // List all your API endpoints here
// const apiEndpoints = [
// // GET request to fetch data from the database
// {
// method: "GET",
// endpoint: "/api/schemas/reccoinTestSchema",
// },
// // POST request to store new data in the database
// {
// method: "POST",
// endpoint: "/api/schemas/reccoinTestSchema",
// data: {
// // collection: "User", // or "Company"
// id: "123",
// name: "John Doe",
// email: "john@example.com",
// walletAddress: "0x123456789",
// verification: true,
// },
// },
// // PUT request to update existing data in the database
// {
// method: "PUT",
// endpoint: "/api/schemas/reccoinTestSchema",
// data: {
// // collection: "User", // or "Company"
// id: "123",
// name: "John Doe",
// email: "john.doe@example.com",
// walletAddress: "0x987654321",
// verification: false,
// },
// },
// // DELETE request to delete data from the database
// {
// method: "DELETE",
// endpoint: "/api/schemas/reccoinTestSchema",
// data: {
// // collection: "User", // or "Company"
// id: "123",
// },
// },
// // Add more endpoints as needed
// ];
// async function callSchemas() {
// try {
// for (const endpoint of apiEndpoints) {
// const { method, endpoint: apiEndpoint, data } = endpoint;
// const config = { method, url: `http://localhost:3000${apiEndpoint}` };
// if (data) {
// config.data = data;
// }
// const response = await axios(config);
// console.log(`API called: ${apiEndpoint}`);
// console.log(response.data); // Output or process the response data as needed
// }
// } catch (error) {
// console.error("Error calling APIs:", error);
// }
// }
// callSchemas();
// console.log("hello");
// const axios = require("axios");
// // List all your API endpoints here
// const apiEndpoints = [
// // "/api/schemas/SampleSchema",
// "/api/schemas/reccoinTestSchema",
// // Add more endpoints as needed
// ];
// async function callSchemas() {
// try {
// for (const endpoint of apiEndpoints) {
// const response = await axios.post(`http://localhost:3000${endpoint}`);
// console.log(`API called: ${endpoint}`);
// console.log(response.data); // Output or process the response data as needed
// }
// } catch (error) {
// console.error("Error calling APIs:", error);
// }
// }
// callSchemas();