Skip to content
D-BOY edited this page Mar 27, 2025 · 1 revision

API Reference

This document describes the API endpoints available in the Programming Task Generator.

Base URL

All endpoints are relative to the base URL where the server is running. Default: http://localhost:3000

API Endpoints

Generate Task from Text Pattern

Generates a programming task based on a text pattern.

  • URL: /generate
  • Method: POST
  • Content-Type: application/json

Request Body

{
  "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
}

Response

  • Success Response: PDF file

    • Content-Type: application/pdf
    • Content: Binary PDF file
  • Error Response: Error details

    • Content-Type: application/json
    • Status: 400, 500
    • Content:
      {
        "error": "Error description",
        "details": "Error details"
      }

Example

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);
});

Generate Task from PDF Pattern

Generates a programming task based on a PDF pattern.

  • URL: /generate-from-pdf
  • Method: POST
  • Content-Type: multipart/form-data

Request Body

  • 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"

Response

  • Success Response: PDF file

    • Content-Type: application/pdf
    • Content: Binary PDF file
  • Error Response: Error details

    • Content-Type: application/json
    • Status: 400, 500
    • Content:
      {
        "error": "Error description",
        "details": "Error details"
      }

Example

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);
});

Error Codes

Status Code Description
400 Bad Request - Missing or invalid parameters
500 Internal Server Error - Error during task generation or PDF creation

Clone this wiki locally