How to make a put request with simple string as request body with JavaScript?

To make a put request with simple string as request body with JavaScript, we set the Content-Type header.

For instance, we write

const response = await axios.put("http://localhost:4000/api/token", "myToken", {
  headers: { "Content-Type": "text/plain" },
});

to call axios.put to make a put request.

The first argument is the request URL, the 2nd argument is the request body, and the last argument is an object with the request headers.

We set the Content-Type header to text/plain to let us send a string request body.