add api get post
This commit is contained in:
16
server/api/surkon/get/index.get.ts
Normal file
16
server/api/surkon/get/index.get.ts
Normal 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",
|
||||
});
|
||||
}
|
||||
});
|
||||
23
server/api/surkon/post/index.post.ts
Normal file
23
server/api/surkon/post/index.post.ts
Normal 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",
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user