sketchfetch
~= fetch for Sketch, using Futures
import fetch from 'sketchfetch';
fetch('https://reqres.in/api/users').fork(
err => log('error, fella'),
res => {
log('result!');
log(res);
}
);
// 'result!'
// { data: […] }
fetch('https://reqres.in/api/users', {
method: 'POST',
body: {
'name': 'Matthew McConaughey'
}
}).fork…
Remember to call fork(err => err, result => result)
on the returned Future to run it!
Rationale
- sketch's JS runtime doesn't support fetch or XMLHttpRequest so we can't use any normal polyfills
- NSURLConnections take a ton of code to set up
- no time for that…
TODOs
- [ ] list out unsupported cases
- [ ] switch to async requests