The fetch api


There are two things that caught me by surprise in the fetch api that aren’t mentioned in the documentation

  • Only https is supported (this is unfortunate for any localhost usage)
  • The request is cached and it’s unclear for how long and how to prevent this (other than the super hacky appending of #${Math.random()})


@Kilian A small suggestion: you could use ngrok to create a secure introspectable tunnel to localhost


Actually, I think Kilian did use ngrok in his demo at our XD plugin event in Amsterdam :slight_smile:


I did, it’s super useful! It’s not really something you could/should ship as part of an XD integration though.


The fetch documentation should also mention it won’t work with binary results like graphics.


I believe you can use with regular http, even though localhost requires https. This is all based on the macOS App Transport Security feature, which by default blocks most insecure communications over the network. Why it applies that to localhost as well is a mystery to me, but I believe using the loopback IP address directly should get around it.

@kerrishotts, do you have any info on the other questions regarding caching and binary responses? I could swear we do support using fetch() to retrieve binary data…


I haven’t though to try using the loopback IP address… that would be a nice workaround.

As to SSL support, I know this will seem a distinction without a difference, but the API we built has no inherent restrictions on accessing insecure resources. Rather, it’s the host environment (macOS w/ ATS) that’s enforcing those restrictions. IIRC (and something to be careful of) Windows should access insecure resources without complaint.

For caching, it’s important to note that we use the OS’s networking APIs for XHR & Fetch. For example, on macOS, we use NSURLSession, which has a cache by default. It’s supposed to respect your response headers, so you should be able to configure your endpoint to expire the cache more frequently. (Let us know if this doesn’t hold, though.)

Finally, for binary data, we do support this, but not via FormData or Blobs yet. Instead, you have to use ArrayBuffer. Both FormData and Blob support is coming soon.