XeNote/posts/Code/JS/Airtable Fetch API.md
2020-11-28 19:36:28 +03:00

26 lines
610 B
Markdown

```javascript
export const Air = {
apiKey: "",
base: "",
url: "https://api.airtable.com/v0/",
init: function ({ apiKey, base }) {
this.apiKey = apiKey;
this.base = base;
},
fetch: async function (table) {
if (this.apiKey && this.base && table) {
const endpoint = `${this.url}${this.base}/${table}?api_key=${this.apiKey}`;
//console.log(endpoint);
const res = await fetch(endpoint, {});
const rj = await res.json();
//console.log("response", rj);
return rj;
} else return null;
}
};
Air.init({ apiKey, base });
Air.fetch("Link")
```
#api-code