Simple REST API that can ping a list of URLs and return their status.
The API is running concurrently, so it can ping multiple URLs at the same time. Also, there is a timeout for each request, so the API won't hang on a slow request, and the ability to stop the process if there is an error on any url. The response also includes the average time of pinging all urls.
- Create
.env
file and copy the content from.env.example
into it. Set your own values for the variables. - To run without docker, run
make run
in the root directory of the project. - To run with docker, run
docker-compose up
in the root directory of the project.
make test
Parameters:
urls
- list of URLs to ping- type:
array
- required:
true
- type:
return_on_err
- iftrue
, the API will return the results as soon as it encounters an error. Iffalse
, the API will ping all URLs and return the results.- type:
boolean
- required:
false
- default:
false
- type:
timeout
- timeout for each request in seconds- type:
integer
- required:
false
- default:
5
- type:
Response:
results
- map of URLs and their status- type:
map
- example:
{"http://example.com": "OK", "http://httpbin.org/get": "OK"}
- type:
average
- average time of pinging all URLs in milliseconds- type:
integer
- example:
241
- type:
Request:
curl -X POST http://localhost:8080/api/v1/ping-urls -d '{"urls": ["http://httpbin.org/get", "http://example.com/404", "https://cloudflare.com/cdn-cgi/trace", "http://www.google.com", "http://www.wikipedia.org"],"return_on_err": false}'
Response:
{
"results": {
"http://example.com/404": "NOT_FOUND",
"http://httpbin.org/get": "OK",
"http://www.google.com": "OK",
"http://www.wikipedia.org": "OK",
"https://cloudflare.com/cdn-cgi/trace": "OK"
},
"average": 241
}