Home  • Programming • JavaScript

Http API request with bearer Token


var url = "https://yourUrl";
var bearer = 'Bearer ' + bearer_token;
fetch(url, {
        method: 'GET',
        withCredentials: true,
        credentials: 'include',
        headers: {
            'Authorization': bearer,
            'X-FP-API-KEY': 'iphone', //it can be iPhone or your any other attribute
            'Content-Type': 'application/json'
        }
    }).then(responseJson => {
        var items = JSON.parse(responseJson._bodyInit);
    })
    .catch(error => this.setState({
        isLoading: false,
        message: 'Something bad happened ' + error
    }));
const url = 'http://192.168.0.151:8089/api';

const token= "";

 fetch(url, 

      {method:'GET',

       headers: {'Authorization':' bearer '+token}

      })

      .then(function(res){

        return res.json();

      })

      .then(function(data) {

        console.log(data);

      });

Comments 0


Copyright © 2024. Powered by Intellect Software Ltd