1.0.7 • Published 4 years ago

remote-service-buffer v1.0.7

Weekly downloads
5
License
ISC
Repository
github
Last release
4 years ago

remote-service-buffer

Buffering result from external fetchAPI, updating only when needed.

Why

If you need to call a fetchAPI more times but you do not want to overload the API server.

You can execute Service more times. Service makes one single call each 5 minutes (default, you can change it), and returns a buffer. If you do not execute Service, it not makes calls to server.

Service is faster. When You execute Service, it first returns a buffer, then performs the buffer update later.

Installation

npm install remote-service-buffer

Example

Calling the same service each second. Service buffers the result and returns it. Service updates buffer after 10 seconds (each 10 seconds if needed).

import service from "remote-service-buffer"

const fetchHeaders = {} //optional

const refreshTime = 1000 * 10 //optional (default is 5 mins)

const myService = new service("http://worldtimeapi.org/api", "/ip", refreshTime, fetchHeaders)

async function loop() {
  console.log(await myService.get())
  setTimeout(loop, 1000)
}
loop()

Refs

https://www.npmjs.com/package/remote-service-buffer

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago