Skip to content
This repository was archived by the owner on Feb 21, 2025. It is now read-only.

Commit 4e53615

Browse files
committed
test: Added a post -> fetch to test communication with BE
1 parent d0d05ba commit 4e53615

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

src/pages/employers/EmployersDashboard.tsx

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,46 @@ const getUniqueOptions = (data: string[]) => Array.from(new Set(data));
1313
const API_URL = import.meta.env.VITE_API_URL;
1414
console.log('Backend API:', API_URL);
1515

16-
fetch(`${API_URL}/v`)
17-
.then((response) => response.json())
18-
.then((data) => console.log(data));
16+
// fetch(`${API_URL}/v`)
17+
// .then((response) => response.json())
18+
// .then((data) => console.log(data));
19+
20+
// POST request to create a new entry
21+
async function postThenFetch() {
22+
try {
23+
// POST operation
24+
const postResponse = await fetch(`${API_URL}/newEntry`, {
25+
method: 'POST',
26+
headers: {
27+
'Content-Type': 'application/json',
28+
},
29+
body: JSON.stringify({
30+
subject: 'Pacorro',
31+
verb: 'loves',
32+
object: 'apples',
33+
isPublic: true,
34+
statement: 'Paco loves apples',
35+
}),
36+
});
37+
if (!postResponse.ok) {
38+
throw new Error(`HTTP error on POST! status: ${postResponse.status}`);
39+
}
40+
const postData = await postResponse.json();
41+
console.log('Successfully posted:', postData);
42+
43+
// GET operation after POST completes
44+
const getResponse = await fetch(`${API_URL}/n/s/Pacorro`);
45+
if (!getResponse.ok) {
46+
throw new Error(`HTTP error on GET! status: ${getResponse.status}`);
47+
}
48+
const getData = await getResponse.json();
49+
console.log(`Fetching from DV: ${JSON.stringify(getData, null, 2)}`);
50+
} catch (error) {
51+
console.error('Error with requests:', error);
52+
}
53+
}
54+
55+
postThenFetch();
1956

2057
const EmployersDashboard: React.FC = () => {
2158
const [filters, setFilters] = useState({

0 commit comments

Comments
 (0)