It's a tradition.....
DevOps/Frontend/Backend/Slacker
@samrocksc
samrocksc@gmail.com
https://github.com/samrocksc/howard
const { default: howard, json } = require('howard');
json(howard('https://swapi.co/api/people/1/'))
.then((res) => {
console.log('res', res);
return res;
});
A library aimed at bringing node into consistency with window.fetch
Aims to build and be compliant with the whatwg fetch spec
function howard(path, options) {
if (options && options.body && !options.method) {
options.method = 'POST';
}
return fetch(path, options);
}
function formData(response) {
return Promise.resolve(response)
.then((res) => {
if (typeof res.formData === 'function') {
return res.formData();
}
return Promise.reject(new Error('Method not implemented'));
});
}
...other ways
if (typeof options.body === 'object' && !(global.FormData && options.body instanceof FormData))
// Form Data
it('handle formData()', function() {
if (isNode) {
this.skip();
}
const data = new FormData();
data.append('testing', 'this')
fetchMock.getOnce(config.url + '/form', { body: data, sendAsJson: false })
const request = formData(howard(config.url + '/form'))
return expect(request).resolves.toEqual(data);
});
const isNode = (process && process.release && process.release.name === 'node');
* For some reason this was one of the hardest things to figure out for me. TypeErrors thrown in this situation can throw a wrench in the entire application.
"test:browser": "mocha-puppeteer test",
"test": "cross-env BABEL_ENV=commonjs mocha --async-only --compilers js:babel-register --recursive",
Isomorphic development isn't for every aspect of programming, but when something can be done universally, let's try to make that happen!