add api get post

This commit is contained in:
2024-11-04 06:45:34 +07:00
parent bd7da15ca3
commit 8c2ad217eb
12 changed files with 1438 additions and 1323 deletions

View File

@@ -0,0 +1,16 @@
import axios from "axios";
export default defineEventHandler(async (event) => {
try {
const response = await axios.get("http://localhost:8082/api/suratkontrol");
// console.log(response.data)
return response.data
} catch (error) {
console.error("Error posting to surat kontrol API:", error);
throw createError({
statusCode: 500,
statusMessage: "Failed to fetch data from surat kontrol API",
});
}
});

View File

@@ -0,0 +1,23 @@
import axios from "axios";
export default defineEventHandler(async (event) => {
// Read the body of the incoming request
const body = await readBody(event);
try {
const response = await axios.post("http://localhost:8082/api/suratkontrol/cari", body, {
headers: {
"Content-Type": "application/json",
},
});
console.log(response.data)
return response.data
} catch (error) {
console.error("Error posting to surat kontrol API:", error);
throw createError({
statusCode: 500,
statusMessage: "Failed to fetch data from surat kontrol API",
});
}
});