Closed guoyunhe closed 3 months ago
Good catch! 👊👍 I will enhance it in next version.
Currently, there is a better way to do that:
import xior from 'xior';
xior.defaults.headers['content-type'] = `application/x-www-form-urlencoded`;
xior.post('/foobar', {foo: 'bar', bar: {a: 1}}); // and support nested object encoding
Fixed in v0.5.4
🥳 now support:
xior.post('/', new URLSearchParams({foo: 'bar'}))
There are some really old back-end systems that don't support JSON API. Instead, they support encoded URI data as body.
axios supports a usage like this:
axios will automatically set
content-type
header toapplication/x-www-form-urlencoded;charset=UTF-8
;However, xior doesn't seem to support this. When I write:
xior will send a request with no
content-type
header, and back-end will reject it.I can fix my code by manually adding the missing header. But maybe it makes sense that xior can do this automatically for users.