2016-08-09 3 views
0

Мой вызов removex для моей конечной точки шлюза AWS API возвращается пустым.Redux fetch возвращается пустым

Curl, Postman или только в браузере, ответ правильный.

export function getRequest() { 
 
    return function (dispatch) { 
 

 
    return fetch("apiGatewayURL", { 
 
     method: 'GET', 
 
     headers: { 
 
     'Content-Type': 'application/json' 
 
     } 
 
    }).then(body => console.log("Calling ",JSON.stringify(body))) 
 
    } 
 
}

Любые предложения о том, что я делаю неправильно здесь?

+0

Предполагая, что вы протестировали конечную точку и знаете, что она работает? – rambossa

+0

Да, конечная точка работает –

ответ

1

Перед тем, как прочитать его, вам нужно позвонить в функцию или text().

export function getRequest() { 
    return function (dispatch) { 

    return fetch("apiGatewayURL", { 
     method: 'GET', 
     headers: { 
     'Content-Type': 'application/json' 
     } 
    }) 
    .then(res => res.json()) 
    .then(body => console.log("Calling ",JSON.stringify(body))) 
    } 

Документация:https://github.com/matthew-andrews/isomorphic-fetch

fetch() документация:https://github.com/github/fetch

+0

Удивительная благодарность за помощь –

0

Ввод Accept в заголовках и вызова .json() на ответ первым.

export function getRequest() { 
    return function (dispatch) { 

    return fetch("apiGatewayURL", { 
     method: 'GET', 
     headers: { 
     'Accept': 'application/json', 
     'Content-Type': 'application/json' 
     } 
    }).then(response => response.json()) 
    .then(body => console.log("Calling ", body)) 
    } 
} 
Смежные вопросы