Fetching json data from GitHub jobs API

Hi campers,

I want to use data from GitHub jobs API for building an app. However i keep getting an error. I am using thhe fetch API.

const url = "https://jobs.github.com/positions.json?description=python&location=new+york";

.then(response => response.json())
.then(data => console.log(data))
.catch(err => console.log(err.name))

I keep getting the error below.

Access to fetch at 'https://jobs.github.com/positions.json?description=python&location=new+york' from origin 'chrome-search://local-ntp' has been blocked by CORS

How can i fix it?

Use a proxy server. GitHub has enabled CORs on their API, so you can not make calls from the client to it when the originating domain is not github.com.

1 Like

If you are building your app through express js, you can install CORS node package via npm / yarn and add it into your app.

var express = require('express')
var cors = require('cors')
var app = express()

1 Like

I just want a Single Page Application built with react. No backend. Can’t i do it without node/express? I simply want to fetch the data, sort using some search parameters and display it in the browser.

I believe you can do it by adding mode property to yout fetch api. But , it is better to have backend for CORS code.

const response = await fetch(URL, {
    method: "GET",
    mode: "cors",

Thanks for the feedback. I think the accepted answer to this stackoverflow question is quite elaborate on how to fix the error.


Add a proxy property to your package.json file as follows:

"proxy" : "https://jobs.github.com"

Change the url as follows:

const url = "/positions.json?description=python&location=new+york"