SQLTerminal.app
now available

XPath.app
now available
Want fresh tech tips in your inbox?

How to Read Response Body HTML with Javascript Fetch Method with React Native

       

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 w/ #javascript #mobile #react-native #cors #response #apis #json

Apps I've Built

XPath Expression Editor
Practice and improve your XPath skills with XPath Editor
Click to buy on the App Store
Photo Location Changer
Easily change the location on your photos and videos
Click here for more info about the app
Photo Date Changer
Easily change the dates and times on your photos and videos
Click here for more info about the app
VocabReminder
English dictionary with notifications so you won't forget what you're studying!
Click here for more info about the app
VocabQuiz
The app that quizzes and scores you on your vocabulary!
Click here for more info about the app