API Calls
Create API
Creating new interfaces in RavenSaaS follows the same rules as creating new interfaces in the NextJS framework.NextJS Framework API Handling
1. Create an interface folder in the app/api directory, and create a new route.ts file
2. Implement the interface business logic
app/api/ping/route.ts
1import { respData, respErr } from "@/lib/response";
2
3export async function POST(req: Request) {
4 try {
5 const { message } = await req.json();
6 if (!message) {
7 return respErr("invalid params");
8 }
9
10 return respData({
11 pong: `received message: ${message}`,
12 });
13 } catch (e) {
14 console.log("test failed:", e);
15 return respErr("test failed");
16 }
17}
Debug API
1. Debug the API using the curl command in the terminal
Terminal
1curl -X POST -H "Content-Type: application/json" \
2 -d '{"message": "hello"}' \
3 http://localhost:3000/api/ping
2. Or debug the API using the REST Client plugin in VS Code

Reference
Last updated on January 5, 2025