2016-08-09 2 views
0

내 AWS API 게이트웨이 엔드 포인트로 가져 오는 호출이 비어 있습니다.redux 가져 오기가 비어 있습니다.

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

읽어보기 전에 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)) 
    } 
} 
관련 문제