Appearance
fetch
访问白马指南。
const response = await fetch('https://www.baima.site/');
const text = await response.text();
console.log(text);访问 SeaTable 。
const API_TOKEN = '123456';
const sql = {sql: `SELECT k, v FROM kv`};
// 生成短期令牌
let url = 'https://cloud.seatable.cn/api/v2.1/dtable/app-access-token/';
let options = {method: 'GET', headers: {Authorization: 'Bearer ' + API_TOKEN}};
let token = '';
let uuid = '';
try {
const response = await fetch(url, options);
const json = await response.json();
token = json.access_token;
uuid = json.dtable_uuid;
} catch (error) {
console.error(error);
}
// 查询记录
url = 'https://cloud.seatable.cn/api-gateway/api/v2/dtables/' + uuid + '/sql/';
options = {method: 'POST', headers: {Authorization: 'Bearer ' + token}, body: JSON.stringify(sql)};
try {
const response = await fetch(url, options);
const json = await response.json();
console.log(json.results);
} catch (error) {
console.error(error);
}