Skip to content

TypeScript

PiotrFerenc edited this page May 14, 2024 · 1 revision
import axios from 'axios';

class Parameters {
  consoleText: string;

  constructor(consoleText: string) {
    this.consoleText = consoleText;
  }
}

class TaskItem {
  sequence: number;
  name: string;
  action: string;

  constructor(sequence: number, name: string, action: string) {
    this.sequence = sequence;
    this.name = name;
    this.action = action;
  }
}

class RequestPayload {
  parameters: Parameters;
  tasks: TaskItem[];

  constructor(parameters: Parameters, tasks: TaskItem[]) {
    this.parameters = parameters;
    this.tasks = tasks;
  }
}

async function main() {
  const url = 'http://localhost:5000/execute';

  const payload = new RequestPayload(
    new Parameters('hallo word'),
    [new TaskItem(1, 'log', 'console')]
  );

  try {
    const response = await axios.post(url, payload, {
      headers: {
        'Content-Type': 'application/json',
      },
    });

    if (response.status === 200) {
      console.log('Response: ' + response.data);
    } else {
      console.log('Error: ' + response.status);
    }
  } catch (error) {
    console.error('Error: ', error);
  }
}

main();
Clone this wiki locally