Skip to content
API that will respond with a given status after a given timeout, written in Nodejs.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
spec
src
.gitignore
.jshintrc
.travis.yml
CONTRIBUTING.md
LICENSE
README.md
app.json
code_of_conduct.md
index.js
package-lock.json
package.json

README.md

Timeout as a Service

Codacy Badge Build Status DepShield Badge

I needed this for a Pen playing with offline detection.

Deploying on Heroku

For fast and simple deployment on Heroku, you can use the button below.

Deploy to Heroku

API

Sports a handeh-dandeh two-parameter API.

Specification

Call the API with your choice of GET, PUT, POST, DELETE with

  • a timeout in miliseconds, and
  • a valid status code you want returned
https://timeout-as-a-service.herokuapp.com/<timeout-in_miliseconds>/<status_code>

You'll get back a JSON object once the request completes:

{
    "waitTime": 1000,
    "status": 200
}

Public API on Heroku:

https://timeout-as-a-service.herokuapp.com/5000/418

CORS Support

CORS allows Origin '*', so you should be able to use this from anywhere.

Security

  • No, it won't reflect a response elsewhere. Obviously. That would be insane.
  • By default wait times are limited to 90 seconds unless you have specified a different maximum wait time with the MAX_WAIT_TIME environment variable.

Example XMLHttpRequest

const timeout = 2000,
const status = 200;
const url = `https://timeout-as-a-service.herokuapp.com/${timeout}/${status}`;

request = new XMLHttpRequest();

request.addEventListener("timeout", () => console.log("Timed out!"));
request.addEventListener("load", data => console.dir(data));

// This will cause a timeout:
request.timeout = timeout - 1000;

request.open("GET", url);
request.send();

Contributing

If you want a feature or have a question:

If unsatisfied by what you find, please file an issue.

If you already have a solution in mind, you can then fork, and submit a pull request, but please file an issue first.

License

MIT

You can’t perform that action at this time.