How to get json data from php RESTAPI


I have an electron windows application, in that I need to fetch a json object from external url (PHP RESTAPI) and store in a variable and manipulate it to display the result.

I have tried http.get, request and fetch method but I am not getting the desired result (JSON Object) either it is coming as empty or html page content. But when the url is entered in browser it is working perfect and hence API is working perfect. I don’t know where I am wrong.

Methods I have tried. (I have used alert to check the output)

**1. request **
var url =“”;

const request = require('request');

request(url, { json: true }, (err, res, body) => {
if (err) { return console.log(err); }

2. http

var url =“”;

http.get(url, function(res){
    var body = '';

    res.on('data', function(chunk){
        body += chunk;

    res.on('end', function(){
        var fbResponse = JSON.parse(body);
        alert("Got a response: ", fbResponse.picture);
}).on('error', function(e){
      alert("Got an error: ", e);
});**strong text**

var url =“”;

fetch(url).then(function(response) {

I have tried all this methods with no success in it.
Kindly suggest the appropriate way to achieve my goal.