Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
70 views
in Technique[技术] by (71.8m points)

javascript - fetch specific information from api in js

i want to fetch specific information from an API that i got, the problem is that when i do that i am limited to 100lists or something from the API and i don't know how to look further.. my code:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
    const api_url =
      "https://data.gov.il/api/3/action/datastore_search?resource_id=8a21d39d-91e3-40db-aca1-f73f7ab1df69";
    async function getData() {
      const response = await fetch(api_url);
      const data = await response.json();
      console.log(data.result.records);
    }
    getData();
      //fetch('https://data.gov.il/api/3/action/datastore_search?resource_id=8a21d39d-91e3-40db-aca1-f73f7ab1df69', {
      //  method: 'GET',
      //  headers: {
      //    'Content-Type': 'application/json'
      //  },
      //  body: JSON.stringify({
      //    
      //  })
      //})
      //  .then(res => {
      //    if (res.ok){
      //      console.log('success')
      //    } else{
      //      console.log('not success')
      //    }
      //  })
      //  .then(data => console.log(data))
    </script>
  </body>
</html>

there is two methods there that i tried, they basically work the same.. when i go to data results records i can see the arrays with the information, i know how to access one of them for example, but all of it is about 1 city, i want to access more cities(on City_name). is it even possible? or the API is limited to this 100 arrays

question from:https://stackoverflow.com/questions/65951490/fetch-specific-information-from-api-in-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I found some query param with this URL, this link limit 100 data. You will set a limit for it same as me in below

https://data.gov.il/api/3/action/datastore_search?resource_id=8a21d39d-91e3-40db-aca1-f73f7ab1df69&limit=200

I think your code should use pagination, You can set a limit and offset. It works with limit and offset


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...