Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@apicase/core
Advanced tools
2 KB library to organize your APIs in a smart way.
There are so many questions about how to good organize work with API in frontend applications
Some people just don't care about and use native fetch, but it's not so flexible and extensible
Some people create their own wrappers (some classes or just functions, or json objects, no matter), but it often becomes unusable in another projects because it was made for specific APIs
In addition, there's another problem - work API is often not separated from application to isolated layer. It means that you can't use your APIs with different projects or with different frameworks
Here is apicase - unified way to create a separated API layer.
Wrap adapter into apicase
method and use it like it's Axios
import { apicase } from '@apicase/core'
improt 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
import { ApiService } from '@apicase/core'
import fetch from '@apicase/adapter-fetch'
const ApiRoot = new ApiService(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
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' } })
adapter-fetch
and adapter-xhr
ApiQueue
apicase-services
apicase-devtools
MIT
FAQs
Core library to make API calls with any adapter
The npm package @apicase/core receives a total of 253 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’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.