@@ -12,9 +12,46 @@ const getUniqueOptions = (data: string[]) => Array.from(new Set(data));
1212const API_URL = import . meta. env . VITE_API_URL ;
1313console . log ( 'Backend API:' , API_URL ) ;
1414
15- fetch ( `${ API_URL } n/s/Alex` )
16- . then ( ( response ) => response . json ( ) )
17- . then ( ( data ) => console . log ( data ) ) ;
15+ // fetch(`${API_URL}/v`)
16+ // .then((response) => response.json())
17+ // .then((data) => console.log(data));
18+
19+ // POST request to create a new entry
20+ async function postThenFetch ( ) {
21+ try {
22+ // POST operation
23+ const postResponse = await fetch ( `${ API_URL } /newEntry` , {
24+ method : 'POST' ,
25+ headers : {
26+ 'Content-Type' : 'application/json' ,
27+ } ,
28+ body : JSON . stringify ( {
29+ subject : 'Pacorro' ,
30+ verb : 'loves' ,
31+ object : 'apples' ,
32+ isPublic : true ,
33+ statement : 'Paco loves apples' ,
34+ } ) ,
35+ } ) ;
36+ if ( ! postResponse . ok ) {
37+ throw new Error ( `HTTP error on POST! status: ${ postResponse . status } ` ) ;
38+ }
39+ const postData = await postResponse . json ( ) ;
40+ console . log ( 'Successfully posted:' , postData ) ;
41+
42+ // GET operation after POST completes
43+ const getResponse = await fetch ( `${ API_URL } /n/s/Pacorro` ) ;
44+ if ( ! getResponse . ok ) {
45+ throw new Error ( `HTTP error on GET! status: ${ getResponse . status } ` ) ;
46+ }
47+ const getData = await getResponse . json ( ) ;
48+ console . log ( `Fetching from DV: ${ JSON . stringify ( getData , null , 2 ) } ` ) ;
49+ } catch ( error ) {
50+ console . error ( 'Error with requests:' , error ) ;
51+ }
52+ }
53+
54+ postThenFetch ( ) ;
1855
1956const EmployersDashboard : React . FC = ( ) => {
2057 const [ filters , setFilters ] = useState ( {
0 commit comments