Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@apicase/core

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apicase/core - npm Package Compare versions

Comparing version 0.13.0 to 0.13.1

2

package.json
{
"name": "@apicase/core",
"version": "0.13.0",
"version": "0.13.1",
"description": "Core library to make API calls with any adapter",

@@ -5,0 +5,0 @@ "main": "cjs/index.js",

@@ -25,6 +25,9 @@ # apicase-core

### Full docs
[**Read on gitbook**](https://kelin2025.gitbooks.io/apicase/content/)
### Basic request
Wrap adapter into `apicase` method and use it like it's Axios
```javascript

@@ -57,29 +60,40 @@ import { apicase } from '@apicase/core'

### Events-based requests handling
Following _"Business logic failures are not exceptions"_ principle,
Apicase separates error handling from request fails:
```javascript
doRequest({ url: '/api/posts' })
.on('done', res => { console.log('Done', res) })
.on('fail', res => { console.log('Fail', res) })
.on('error', err => { console.error(err) })
doRequest({ url: "/api/posts" })
.on("done", res => {
console.log("Done", res)
})
.on("fail", res => {
console.log("Fail", res)
})
.on("error", err => {
console.error(err)
})
```
### Apicase services
Move your API logic outside the main application code
```javascript
import { ApiService } from '@apicase/core'
import fetch from '@apicase/adapter-fetch'
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 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)
})
const AuthService = ApiRoot.extend({ url: "auth" }).on("done", res => {
localStorage.setItem("token", res.body.token)
})
AuthService.doRequest({
body: { login: 'Apicase', password: '*****' }
body: { login: "Apicase", password: "*****" }
})

@@ -89,11 +103,13 @@ ```

### Request queues
Keep correct order of requests using queues
```javascript
import { ApiQueue } from '@apicase/core'
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' } })
queue.push(SendMessage.doRequest, { body: { message: "that stuff" } })
queue.push(SendMessage.doRequest, { body: { message: "really" } })
queue.push(SendMessage.doRequest, { body: { message: "works" } })
```

@@ -100,0 +116,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc