Written by Sean Behan on Mon Jul 17th 2017

In React Native you see a lot of tutorials and articles using the fetch method when interacting with JSON APIs. It's great for this and the the pattern looks like this

fetch(url).then((resp)=>{ return resp.json() }).then((json)=>{ console.log(json) })

But what if the API you're working with is returning HTML? The solution is pretty simple but kind of hard to find online because it's not as common as working with JSON.

Instead of returning resp.json() just return resp.text() like this

fetch(url).then((resp)=>{ return resp.text() }).then((text)=>{ console.log(text) })

This will give you the response body in plain text.

Tagged with..
#javascript #mobile #react-native #cors #response #apis #json

Just finishing up brewing up some fresh ground comments...