Skip to main content
Question

Javascript Fetch API compatibility with Quick Base?

  • August 28, 2018
  • 0 replies
  • 111 views

I'm attempting to use a code page to do some calculations... My main question is the Fetch API, as referenced here: https://scotch.io/tutorials/how-to-use-the-javascript-fetch-api-to-get-data

Is this Fetch command compatible in the version of JavaScript that Quick Base uses?

  • Quickbase Alumni
  • August 28, 2018
javascript is not a quickbase thing, its a web standard. check out Mozilla Developer Network and W3Schools to learn about web languages. now i will give you a fast class on fetch:


fetch requires at least a url in position 1 and option init (initialise instructions)

example:

var url = "https://yourquickbasedomain.quickbase.com/db/tableid?a=APIAddrecordetcetcetc";
var init = { 
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/xml"
},
body: //put you body here

};

fetch(url, init).then(response => response.text()).then(str => (new DOMParser()).parseFromString(str, "text/xml")).then(function(xml) {
let rid = $("rid", xml).text()
console.log(rid);
})

  • Quickbase Alumni
  • August 28, 2018
Fetch is a JavaScript API that replaces XMLHTTPRequest and it is fully supported in all modern browsers:

Can I Use Fetch
https://caniuse.com/#feat=fetch

While Fetch is clearly the future there are some reasons you may not want to use it with QuickBase:

1) Fetch is a low level API and requies you send cookies (via credentials: "include") with each request.

2) With Fetch there is no corresponding $.ajaxSetup() method to include the application token with each request as there is with jQuery's AJAX methods

3) While Fetch returns a promise it is a native promise not a jQuery promise. Luckily you can convert a jQuery promise into a native promise using code similar to this:
var nativePromise = Promise.resolve(
  $.ajax(...);
  );
4) Fetch does not support passing an object for the data (you have to pass a string, blob, formdata)


The reasons to use Fetch are compelling:

1) There is a bug in the version of jQuery QuickBase uses (ver 1.7.1) which breaks chaining.

2) Service Workers only support Fetch (no XMLHTTPRequest or jQuery)

3) Just about every web related API is asynchronous today and returns a native promise. Since Fetch returns a native promise it works seamlessly with native promises.

4) Fetch support FormData which makes it trivial to clone a QuickBase form and submit it using Fetch as FormData