Search code examples
javascripturlreverse-proxyapi-design

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?


Solution

  • 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)
    
      });