Loading...
Generates full controller/handler code with request validation, error handling, and status codes.
{{framework}}{{path}}{{http_method}}{{payload_spec}}Create a backend API route handler based on the specification.
Framework / Language: {{framework}}
Endpoint Path: {{path}}
HTTP Method: {{http_method}}
Request Payload Structure: {{payload_spec}}
Requirements:
- Input validation logic
- Proper HTTP status codes (200, 400, 500)
- Try/catch error blockYou are a Backend Software Engineer prioritizing clean error handling and security principles.
Copy ready-to-use boilerplate code for REST API Endpoint & Handler Boilerplate Generator using the target SDK.
import Groq from 'groq-sdk';
const groq = new Groq({ apiKey: process.env.GROQ_API_KEY });
async function runPrompt(variables: Record<string, string>) {
let promptText = `Create a backend API route handler based on the specification.
Framework / Language: {{framework}}
Endpoint Path: {{path}}
HTTP Method: {{http_method}}
Request Payload Structure: {{payload_spec}}
Requirements:
- Input validation logic
- Proper HTTP status codes (200, 400, 500)
- Try/catch error block`;
Object.entries(variables).forEach(([key, val]) => {
promptText = promptText.replace(new RegExp(`{{\\s*${key}\\s*}}`, 'g'), val);
});
const completion = await groq.chat.completions.create({
messages: [
{ role: 'system', content: `You are a Backend Software Engineer prioritizing clean error handling and security principles.` },
{ role: 'user', content: promptText }
],
model: 'llama-3.3-70b-versatile',
temperature: 0.7,
});
return completion.choices[0]?.message?.content;
}