Search code examples
pythonajaxrestbokeh

Are there any sample API without CORS?


Currently i need a sample API to test AjaxDataSource on my Bokeh project( checked all API from this one https://github.com/toddmotto/public-apis)

But all of them require Cross-Origin Resource Sharing (CORS)

from datetime import date
from random import randint
from bokeh.models import AjaxDataSource, CustomJS
from bokeh.models.widgets import DataTable, DateFormatter, TableColumn
from bokeh.models.layouts import WidgetBox
from bokeh.plotting import show, figure
import numpy as np
from flask import Flask, jsonify, make_response, request

from bokeh.plotting import figure, show
from bokeh.models import AjaxDataSource, CustomJS

adapter1 = CustomJS(code="""
    const result = {x: [], y: []}
    const json = cb_data.response
    console.log("Hi")
    for (var key in json) {
       if (json.hasOwnProperty(key)) {
          result.x.push(json[key].nome);
          result.y.push(json[key].codigo);
       }
    }
    console.log(result)
    return result
""")

source = AjaxDataSource(data_url='https://parallelum.com.br/fipe/api/v1/carros/marcas', adapter = adapter1)

columns = [
        TableColumn(field="x", title="Nome"),
        TableColumn(field="y", title="Codigo"),
    ]
data_table = DataTable(source=source, columns=columns, width=400, height=280)

show(data_table)

So i have this problem

failed

Are there any sample API that doesn't not require CORS out there?

Thanks


Solution

  • Try this api : https://www.geojs.io/docs/v1/endpoints/country/

    e.g.

    
    fetch("https://get.geojs.io/v1/ip/country.json?ip=8.8.8.8")
      .then(function(data) {
        return data.json();
      })
      .then(function(response) {
        console.log(JSON.stringify(response));
      })