Created
January 20, 2020 10:09
-
-
Save Frenchcooc/ef58366b6ec6acf89dfdf39a158be4e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Require the library and client | |
const circuitBreaker = require("opossum") | |
const apiClient = require("our-example-api-client") | |
// Our example request | |
const getPosts = (req, res, next) => { | |
// Wrap our client get method in the circuit breaker | |
const breaker = circuitBreaker(apiClient.get, { | |
timeout: 3000, | |
errorThresholdPercentage: 50, | |
resetTimeout: 5000 | |
}) | |
// Call the API from within the circuit breaker | |
return breaker | |
.fire("/api/posts") | |
.then(res.json) | |
.catch(next) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment