Qualima
Qualima

Reputation: 163

Vue, Send a GET request with the header configuration to the server in Vue JS

I would like to send an GET request to a server with the following header when the component is being created in a vue js component:

How should I write this request?

curl:

-X GET "http://134.140.154.121:7075/rest/api/Time" -H "accept: application/json" -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IkFZd21VU0Jvd2lxcVRSRG81NTctVFEiLCJ0eXAiOiJhdCtqd3QifQ.eyJuYmYiOjE1OTMfryyw"

And the information it sends is as follows:

Response body:

{ "values": { "value": "string" } }

How do I send header and outh settings along with the request?

Upvotes: 0

Views: 1947

Answers (1)

Dhruv Tailor
Dhruv Tailor

Reputation: 2751

  fetch("http://134.140.154.121:7075/rest/api/Time",{
        method:'GET',
        header:{
             'accept': 'application/json',
             'Authorization': 'Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IkFZd21VU0Jvd2lxcVRSRG81NTctVFEiLCJ0eXAiOiJhdCtqd3QifQ.eyJuYmYiOjE1OTMfryyw'
        }
    })
.then(res => res.json())
.then(res => {
      // Use res
}

Upvotes: 1

Related Questions