Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
68 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...