Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@apicase/core
Advanced tools
A 2 KB library to organize your APIs in a smart way.
There are so many questions about how to properly organize and work with APIs in frontend applications.
Some people just don't think about it much; they use native fetch
, but it's not very flexible or extensible. Some people create their own wrappers (classes, functions, or json objects), but those often become unusable in other projects because they were made for specific APIs.
There's another problem—the API is often not separated from the application into an isolated layer. It means that you can't reuse your APIs with different projects or frameworks.
Here is apicase—a unified way to create that isolated API layer.
Library sources are transpiled with babel-preset-env but we don't add polyfills to our library to save its size and avoid code duplicates if your project already has polyfills.
So here's the list of features you need to know:
@apicase/adapter-fetch
. You might need fetch polyfill to work with IE 11 or you can just use @apicase/adapter-xhr
[caniuse]@apicase/adapter-fetch
to implement req.cancel()
and hasn't polyfills. Apicase will work well if AbortController is not supported but note that request just won't be really cancelled [caniuse]Wrap adapter into apicase
method and use it like it's Axios
import { apicase } from '@apicase/core'
import fetch from '@apicase/adapter-fetch'
const doRequest = apicase(fetch)
const { success, result } = await doRequest({
url: '/api/posts/:id',
method: 'POST',
params: { id: 1 },
body: {
title: 'Hello',
text: 'This is Apicase'
},
headers: {
token: localStorage.getItem('token')
}
})
if (success) {
console.log('Yay!', result)
} else {
console.log('Hey...', result)
}
Following "Business logic failures are not exceptions" principle,
Apicase separates error handling from request fails:
doRequest({ url: "/api/posts" })
.on("done", res => {
console.log("Done", res)
})
.on("fail", res => {
console.log("Fail", res)
})
.on("error", err => {
console.error(err)
})
Move your API logic outside the main application code
Check out @apicase/services
repository and docs page for more info
import fetch from "@apicase/adapter-fetch"
import { ApiService } from "@apicase/services"
const ApiRoot = new ApiService({
adapter: fetch,
url: "/api"
})
.on("done", logSucccess)
.on("fail", logFailure)
const AuthService = ApiRoot.extend({ url: "auth" }).on("done", res => {
localStorage.setItem("token", res.body.token)
})
AuthService.doRequest({
body: { login: "Apicase", password: "*****" }
})
Keep correct order of requests using queues
Check out docs page for more info
import { ApiQueue } from "@apicase/core"
const queue = new ApiQueue()
queue.push(SendMessage.doRequest, { body: { message: "that stuff" } })
queue.push(SendMessage.doRequest, { body: { message: "really" } })
queue.push(SendMessage.doRequest, { body: { message: "works" } })
apicase-devtools
MIT
FAQs
Core library to make API calls with any adapter
The npm package @apicase/core receives a total of 214 weekly downloads. As such, @apicase/core popularity was classified as not popular.
We found that @apicase/core 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.