J
J
Jorlian2020-04-17 16:16:23
JavaScript
Jorlian, 2020-04-17 16:16:23

DELETE request to the backend, how to correctly fill in the headers field in fetch?

there is a method in the backend that waits for req.getHeader("teacherId")
from the front how to correctly fill in the headers field in fetch?
5e99abc857a74033697184.png
with insomnia the request happens

Tried like this:

fetch('http://localhost:8080/teachers', {
        method: 'DELETE',
        headers: {
            "teacherId": 8
        }
    })

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2020-04-17
@Nc_Soft

The heading is put, only there the Teacherid becomes

const fetch = require('node-fetch');

fetch('https://httpbin.org/delete', {
  method: 'DELETE',
  headers: {
    "teacherId": 8
  }
})
  .then(res => res.text())
  .then(text => {
    console.log(text);
  });

answer
/usr/local/bin/node /Users/evgenij/projects/fetch.js
{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip,deflate", 
    "Host": "httpbin.org", 
    "Teacherid": "8", 
    "User-Agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)", 
    "X-Amzn-Trace-Id": "Root=1-5e99af90-fe7e43f7f3d1149a814fd762"
  }, 
  "json": null, 
  "origin": "*******", 
  "url": "https://httpbin.org/delete"
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question