Skip to content

vadimpk/url-pinger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple URL Pinger

Description

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.

Usage

  1. Create .env file and copy the content from .env.example into it. Set your own values for the variables.
  2. To run without docker, run make run in the root directory of the project.
  3. To run with docker, run docker-compose up in the root directory of the project.

Tests

make test

API

POST /api/v1/ping-urls

Parameters:

  • urls - list of URLs to ping
    • type: array
    • required: true
  • return_on_err - if true, the API will return the results as soon as it encounters an error. If false, the API will ping all URLs and return the results.
    • type: boolean
    • required: false
    • default: false
  • timeout - timeout for each request in seconds
    • type: integer
    • required: false
    • default: 5

Response:

  • results - map of URLs and their status
    • type: map
    • example: {"http://example.com": "OK", "http://httpbin.org/get": "OK"}
  • average - average time of pinging all URLs in milliseconds
    • type: integer
    • example: 241

Example

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
}

Architecture

Screenshot 2024-01-04 at 21 02 01

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published