url with reverse proxy queries only first url parameter

I am building a react app that displays job data as cards from the github jobs api https://jobs.github.com/api just like this app https://jobs.bhanuteja.dev/. In order to fetch data from the github api since CORS is enabled I had to use a reverse proxy . The problem is that my url with the reverse proxy added only queries the first url parameter and does not continue to the second.

DOES NOT QUERY FOR LOCATION

https://api.allorigins.win/raw?url=https://jobs.github.com/positions.json?search=react&location=new+york

normal url without proxy queries location

https://jobs.github.com/positions.json?search=react&location=new+york

What can I do to change this ?

Answer

Just follow the documentation and examples for the allorigins.win API and use encodeURIComponent()

const giturl ='https://jobs.github.com/positions.json?search=react&location=new+york';

fetch(`https://api.allorigins.win/get?url=${encodeURIComponent(giturl)}`)
  .then(res => res.json())
  .then(data => {
    const jobs = JSON.parse(data.contents)
               .map(({location,company }) => ({company,location}))

    console.log(jobs)

  });

Leave a Reply

Your email address will not be published. Required fields are marked *