Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@apicase/adapter-xhr
Advanced tools
XHR adapter for apicase-core
XHR adapter is out-of-the-box adapter and it's installed in apicase-core by default
apicase.call({
adapter: 'xhr',
url: '/api/posts',
method: 'GET',
headers: { token: 'my_secret_token' },
query: { userId: 1 }
})
.then(console.log)
.catch(console.error)
It will call:
var xhr = new XMLHttpRequest()
xhr.open('GET', '/api/posts?userId=1', true)
xhr.onload = function onload (e) {
// See validators
if (isSuccess(e.target, e)) {
console.log(e)
} else {
console.error(e)
}
}
xhr.setRequestHeader('token', 'my_secret_token')
xhr.send(null)
Fetch adapter also has path-to-regexp to pass urls params smarter. Params are stored in params property
apicase.call({
adapter: 'xhr',
url: '/api/posts/:id',
params: { id: 1 }
})
// => GET /api/posts/1
If you want to create dynamic headers object so you can pass headers property as function that returns headers object
apicase.call({
adapter: 'fetch',
url: '/api/posts',
method: 'POST',
headers: () => ({
token: localStorage.getItem('token')
})
})
It will be called every time you make a request so if token will be removed, header won't be sent too.
I've added possibility to customizate resolve/reject apicase requests with validator callback.
It accepts xhr target and onload event
apicase.call({
adapter: 'fetch',
url: '/api/posts',
validator: (target, event) =>
target.status >= 200 && target.status <= 299
})
Default validator function is here:
function defaultValidator (target, event) {
return (target.status >= 200 && target.status <= 299) || target.status === 304
}
I know that people use XHR instead of fetch because of calls abortion and upload progress handling.
So there are two custom hooks for that - progress and aborted:
apicase.call({
url: '/upload',
method: 'POST',
body: ...,
hooks: {
// xhr.onprogress
progress (event, next) {
console.log(event)
next()
},
// xhr.onabort
aborted (event, next) {
console.log(event)
next()
}
}
})
NOTE: event also has options property with request options because apicase calls all hooks with options injected.
MIT
FAQs
XHR adapter for apicase-core
We found that @apicase/adapter-xhr demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.