'how to pass header in get method?

i am sending the quantity through the query param, but i want to send it through headers is it possible like the delete method below?

fetch(
      `https://localhost:5000/books?quantity=${quantity}`
    )
      .then((res) => res.json())
      .then((data) => {
        setBooks(data)
        setLoading(false)
      })
 fetch(url, {
      method: "DELETE",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ id: deleteId }),
    })
      .then((res) => res.json())
      .then((data) => {
        setPopup(false)
        const rest = books.filter((book) => book._id !== deleteId)
        setBooks(rest)
      })


Solution 1:[1]

use this

fetch(`https://localhost:5000/books?quantity=${quantity}`, {
  method: 'GET',
  headers: {
       "Content-Type": "application/json"
        }
    });
 .then((res) => res.json())
  .then(data => {
    console.log(data)
  })

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Moniruzzaman