2016-08-09 27 views
0

我對我的AWS API網關端點的redux提取調用返回空。Redux提取返回空

捲曲,郵差或只是在瀏覽器中,響應是正確的。

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

在讀取它之前,您需要調用json()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)) 
    } 
}