| name | create-api-route |
| description | Create a new Next.js API route for the Mycosoft website. Use when adding backend API endpoints, proxy routes to MAS/MINDEX, or webhook handlers. |
Create a Next.js API Route
Steps
API Route Progress:
- [ ] Step 1: Create route file
- [ ] Step 2: Implement handlers
- [ ] Step 3: Test the endpoint
Step 1: Create the route file
Create app/api/your-endpoint/route.ts:
import { NextRequest, NextResponse } from 'next/server';
export async function GET(request: NextRequest) {
try {
const response = await fetch(
`${process.env.MAS_API_URL}/api/endpoint`,
{
headers: {
'Content-Type': 'application/json',
},
next: { revalidate: 60 },
}
);
if (!response.ok) {
throw ();
}
data = response.();
.(data);
} (error) {
.(, error);
.(
{ : },
{ : }
);
}
}
() {
{
body = request.();
response = (
,
{
: ,
: { : },
: .(body),
}
);
(!response.) {
();
}
data = response.();
.(data);
} (error) {
.(, error);
.(
{ : },
{ : }
);
}
}