Need help on API Integrations and Responsive Screen Design #10244
Salmankhan033
started this conversation in
General
Replies: 1 comment
-
What you are seeing in the console is the a Fetch Response - you need to convert it to json if you want to access json data: const response = await fetch(
'https://api.nytimes.com/svc/books/v3/lists/current/hardcover-fiction.json?api-key=XP2mJDptKJntuwHEDG8hBReABWvuO7A1'
)
.then((res) => {
if (res.ok) {
// if the response was OK - get the json data...
return res.json();
}
// handle error responses in some way. For example - throw and catch below...
console.log({
status: res.status,
statusText: res.statusText,
});
throw new Error('Could not fetch books.');
})
.then((res) => {
console.dir('result', res);
console.dir('books', res.results.books);
})
.catch((err) => {
console.error(err);
}); Note: I added basic error handling - but in real apps you will need to handle bad responses in some way that makes sense for the app. (ie. show an error to the user) fetch reference: https://developer.mozilla.org/en-US/docs/Web/API/fetch#examples As for building your UI - refer to the various layouts available: I generally use GridLayout for most of my layouts with "fluid" sizes like |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am new to Native Script,
I call the API :
OutPut console is :
My question is that in console did not show full data, it show <...> and stop. I want to access res.results.books but can’t.
also, I take the API response as a local variable but also show the same outPut console(mean data is in huge amount).
how to handle it please help me.
Also, I have another question, I jump from React_Native In react native I use the
react-native-responsive-screen
for responsive UI it native script how ho handle responsive UI(Simple % library etc)Beta Was this translation helpful? Give feedback.
All reactions