-
Notifications
You must be signed in to change notification settings - Fork 0
Api
D-BOY edited this page Mar 27, 2025
·
1 revision
This document describes the API endpoints available in the Programming Task Generator.
All endpoints are relative to the base URL where the server is running.
Default: http://localhost:3000
Generates a programming task based on a text pattern.
-
URL:
/generate -
Method:
POST -
Content-Type:
application/json
{
"pattern": "string", // Required: The instruction pattern
"taskTypes": ["string"], // Required: Array of task types
"languages": ["string"], // Required: Array of programming languages
"outputLanguage": "string", // Required: Language for instructions
"withAlgorithmChart": boolean, // Optional: Include algorithm flowchart
"withAppStructure": boolean, // Optional: Include app structure diagram
"withGuiVisualization": boolean // Optional: Include GUI mockup
}-
Success Response: PDF file
-
Content-Type:
application/pdf - Content: Binary PDF file
-
Content-Type:
-
Error Response: Error details
-
Content-Type:
application/json - Status: 400, 500
-
Content:
{ "error": "Error description", "details": "Error details" }
-
Content-Type:
fetch('/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
pattern: "Create a program that...",
taskTypes: ["algorithm", "web application"],
languages: ["javascript", "python"],
outputLanguage: "English",
withAlgorithmChart: true,
withAppStructure: true,
withGuiVisualization: false
})
})
.then(response => {
if (response.ok) {
return response.blob();
}
throw new Error('Network response was not ok');
})
.then(blob => {
// Create a download link for the PDF
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'programming-task.pdf';
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
});Generates a programming task based on a PDF pattern.
-
URL:
/generate-from-pdf -
Method:
POST -
Content-Type:
multipart/form-data
-
pdfFile: (file) Required: The PDF file containing the pattern -
taskTypes: (string) Required: JSON string array of task types -
languages: (string) Required: JSON string array of programming languages -
outputLanguage: (string) Required: Language for instructions -
withAlgorithmChart: (string) Optional: "true" or "false" -
withAppStructure: (string) Optional: "true" or "false" -
withGuiVisualization: (string) Optional: "true" or "false"
-
Success Response: PDF file
-
Content-Type:
application/pdf - Content: Binary PDF file
-
Content-Type:
-
Error Response: Error details
-
Content-Type:
application/json - Status: 400, 500
-
Content:
{ "error": "Error description", "details": "Error details" }
-
Content-Type:
const formData = new FormData();
formData.append('pdfFile', document.getElementById('pdfFile').files[0]);
formData.append('taskTypes', JSON.stringify(["algorithm", "desktop application"]));
formData.append('languages', JSON.stringify(["java", "c++"]));
formData.append('outputLanguage', "English");
formData.append('withAlgorithmChart', "true");
formData.append('withAppStructure', "true");
formData.append('withGuiVisualization', "true");
fetch('/generate-from-pdf', {
method: 'POST',
body: formData
})
.then(response => {
if (response.ok) {
return response.blob();
}
throw new Error('Network response was not ok');
})
.then(blob => {
// Create a download link for the PDF
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'programming-task.pdf';
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
});| Status Code | Description |
|---|---|
| 400 | Bad Request - Missing or invalid parameters |
| 500 | Internal Server Error - Error during task generation or PDF creation |