Sending JSON to server using AJAX in JavaScript

You can send data to a server in the form of JSON. This is done in the following way:

public/client.jsbutton.addEventListener('click', function() {
  let promise = fetch('/handler/', {
    method: 'post',
    body: JSON.stringify([1, 2, 3, 4, 5]),
    headers: {
      'Content-Type': 'application/json',
    },
  });
});

On the server, the request body will be in body:

server.jsexport default {
  '/handler/': function({ body }) {
    console.log(body);
  }
}

Let's unpack the JSON received by the server:

server.jsexport default {
  '/handler/': function({ body }) {
    console.log(JSON.parse(body));
  }
}
Задание 1

Send an array of data to a server. Let the server find the sum of this array elements and send back.