api-pagination icon indicating copy to clipboard operation
api-pagination copied to clipboard

Access Link header in fetch response

Open mikeheft opened this issue 6 years ago • 4 comments

I'm consuming an API that I paginated with your gem. How would I gain access to the link header in the fetch response? I am using React to consume the endpoint, right now when I try response.headers it's just an empty json object.

    fetch('url')
      .then(response => {
        return response.json()})
      .then(data => {
        this.setState({recomms: data})
        localStorage.setItem('movies', JSON.stringify(data))
       })

mikeheft avatar Jan 24 '18 21:01 mikeheft

response.headers.get('Link') got me access to it 😃 However, looking at other tutorials, the links come through in the body, and they're not doing that in my response

mikeheft avatar Jan 24 '18 22:01 mikeheft

@mikeyduece What tutorials are you looking at?

davidcelis avatar Jan 24 '18 23:01 davidcelis

This (response.headers.get('Link')) will work if response type is basic.

else if response type is cors then server restricts the headers you can view to Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, and Pragma.

saihgal avatar Apr 15 '19 17:04 saihgal