@@ -13,9 +13,46 @@ const getUniqueOptions = (data: string[]) => Array.from(new Set(data));
1313const API_URL = import . meta. env . VITE_API_URL ;
1414console . 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
2057const EmployersDashboard : React . FC = ( ) => {
2158 const [ filters , setFilters ] = useState ( {
0 commit comments