目前我需要一个示例API来测试我的Bokeh项目中的AjaxDataSource(从这一个https://github.com/toddmotto/public-apis检查所有API)
但所有这些都需要跨源资源共享(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)
所以我有这个问题
是否有任何不需要CORS的示例API?
谢谢
试试这个api:https://www.geojs.io/docs/v1/endpoints/country/
EG
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));
})