Bladeren bron

postgrest: export make_api() instead of api

master
Bing Sun 5 jaren geleden
bovenliggende
commit
50218132b4
Getekend door: sunb GPG sleutel-ID: F7795F8C590626AB
1 gewijzigde bestanden met toevoegingen van 16 en 7 verwijderingen
  1. +16
    -7
      src/postgrest.js

+ 16
- 7
src/postgrest.js Bestand weergeven

@@ -1,5 +1,3 @@
/* api wrapper */

// utilities
// generate downloadable csv
const download = (options={}) => {
@@ -109,8 +107,21 @@ const _make_api = (api_root, need_auth=true) => {

// expose authentication module
auth: _auth,
}
}

// wrap m.request with authentication validation
/* api wrapper */
/*
* api.request(options): all options will be forwarded to m.request, except a
* few:
*
* 1. options.queries: an array of object '{label: <>, value: <>, op: <>}' to
* build postgrest query easily
*/

export default (api_root, auth={}) => {
return {
// wrap m.request with authentication validation if demanded
request: (options = {}) => {
/* normalize arguments */
if (typeof options === 'string') {
@@ -119,11 +130,11 @@ const _make_api = (api_root, need_auth=true) => {

/* normalize url */
if (options.url.startsWith('/'))
options.url = _root + options.url
options.url = api_root + options.url

/* normalize headers */
// 1. check if auth is required
if (need_auth) {
if (false/*need_auth*/) {
// insert auth header if availible
if (_auth.token()) {
options.headers = {
@@ -193,5 +204,3 @@ const _make_api = (api_root, need_auth=true) => {
}
}
}

export default _make_api('https://api-dev.uidt.net/phanerozoic/v1', false)

Laden…
Annuleren
Opslaan