Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Check-Host API

A clean, typed REST API wrapper around Check-Host.net β€” run ping, HTTP, and TCP availability checks from global monitoring nodes and get back normalized, easy-to-consume JSON.

TypeScript Node.js Express License


Table of Contents


About

Check-Host.net is a free service that checks the availability and performance of hosts (websites, servers, IPs) from monitoring nodes distributed around the world.

Its public API is powerful but low-level: you fire a check, receive a request_id, then poll a separate endpoint for results that come back as deeply nested, positional arrays. Check-Host API sits in front of it and provides:

  • A small, predictable REST surface (/check/*, /node/*).
  • Location-based node selection β€” request checks by country/location code instead of memorizing raw node hostnames.
  • Normalized responses β€” the raw positional arrays returned by Check-Host are mapped into clean, self-describing JSON objects.
  • A consistent response envelope (success, message, data, error) for every endpoint.

Features

  • βœ… Ping, HTTP, and TCP checks against any host.
  • 🌍 Global node discovery with an in-memory cache, grouped by location code.
  • 🧭 Select nodes by location (e.g. us, de, ir) rather than raw hostnames.
  • 🧹 Response mappers that turn Check-Host's raw output into structured results (latency, status, IP, HTTP status code, etc.).
  • 🧱 Layered architecture β€” routes, controllers, usecases, services, and utilities cleanly separated.
  • πŸ›‘οΈ Centralized error handling and a uniform success/failure envelope.
  • πŸ”€ Fully written in TypeScript with typed domain models.

Architecture

The project follows a layered / clean-architecture style where each request flows through well-defined boundaries:

Route  β†’  Controller  β†’  Usecase  β†’  Service  β†’  Check-Host.net
                              β”‚
                              └─ maps raw response β†’ normalized JSON
Layer Responsibility
Routes Declare HTTP endpoints and bind them to controllers.
Controllers Parse the request, delegate to a usecase, and shape the HTTP status.
Usecases Business logic: validate input, resolve nodes, orchestrate services.
Services Talk to the Check-Host.net HTTP API via a shared Axios client.
Utils Response envelope, node cache, and raw-to-clean result mappers.

Getting Started

Prerequisites

  • Node.js β‰₯ 18
  • npm (or a compatible package manager)

Installation

# Clone the repository
git clone https://github.com/mehdiyahyavi/checkhost-api.git
cd checkhost-api

# Install dependencies
npm install

Running

# Development (hot reload via nodemon + ts-node)
npm run dev

# Production
npm run build   # compiles TypeScript to dist/
npm start       # runs dist/server.js

The server starts on http://localhost:3000 by default.

Configuration

Configuration is read from environment variables (via dotenv). Create a .env file in the project root:

# Port the API server listens on
PORT=3000

# Runtime environment
NODE_ENV=development
Variable Default Description
PORT 3000 HTTP port for the API server.
NODE_ENV development Runtime environment name.

API Reference

Base URL: http://localhost:3000

All responses share the same envelope:

{
  "success": true,
  "message": "Request success",
  "data": {},
  "error": null
}

Nodes

POST /node/refresh

Fetches the current list of monitoring nodes from Check-Host, groups them by location code, and stores them in the in-memory cache. Run this once before performing checks so that location-based selection works.

curl -X POST http://localhost:3000/node/refresh

GET /node

Returns the cached nodes, grouped by location code.

curl http://localhost:3000/node
{
  "success": true,
  "message": "nodes Found in cache",
  "data": {
    "us": ["us1.node.check-host.net", "us2.node.check-host.net"],
    "de": ["de1.node.check-host.net"]
  }
}

Checks

Each check endpoint accepts the target host and an array of location codes. It returns a request_id that you later exchange for results.

Method Endpoint Body
POST /check/ping { "host": string, "location": string[] }
POST /check/http { "host": string, "location": string[] }
POST /check/tcp { "host": string, "location": string[] }

Example β€” Ping check

curl -X POST http://localhost:3000/check/ping \
  -H "Content-Type: application/json" \
  -d '{ "host": "example.com", "location": ["us", "de"] }'
{
  "success": true,
  "message": "Request success",
  "data": "a1b2c3d4-0000-1111-2222-333344445555"
}

The data field is the request_id. Use it with /check/result.

Results

POST /check/result

Retrieves and normalizes the result of a previously submitted check.

Field Type Description
request_id string The ID returned by a /check/* endpoint.
type string One of ping, http, tcp.
curl -X POST http://localhost:3000/check/result \
  -H "Content-Type: application/json" \
  -d '{ "request_id": "a1b2c3d4-...", "type": "ping" }'

Normalized ping response:

{
  "success": true,
  "message": "Data Success",
  "data": [
    {
      "node": "us1.node.check-host.net",
      "ip": "93.184.216.34",
      "pings": ["0.042", "0.041", "Timeout", "0.043"]
    }
  ]
}

ℹ️ Check-Host runs checks asynchronously. If you request results immediately, some nodes may not have finished yet β€” poll again after a short delay.

Typical Workflow

sequenceDiagram
    participant Client
    participant API as Check-Host API
    participant CH as Check-Host.net

    Client->>API: POST /node/refresh
    API->>CH: GET /nodes/hosts
    API-->>Client: nodes cached βœ”

    Client->>API: POST /check/ping { host, location[] }
    API->>CH: GET /check-ping?host=&node=...
    CH-->>API: request_id
    API-->>Client: request_id

    Client->>API: POST /check/result { request_id, type }
    API->>CH: POST /check-result/{request_id}
    CH-->>API: raw results
    API-->>Client: normalized JSON
Loading
  1. Refresh nodes β†’ POST /node/refresh
  2. (Optional) List nodes β†’ GET /node
  3. Start a check β†’ POST /check/ping | /check/http | /check/tcp β†’ receive request_id
  4. Fetch results β†’ POST /check/result with the request_id and type

Project Structure

src/
β”œβ”€β”€ app.ts                       # Express app setup & middleware
β”œβ”€β”€ server.ts                    # HTTP server bootstrap
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ config.ts                # Env-based configuration
β”‚   └── host-request-config.ts   # Axios client & Check-Host route map
β”œβ”€β”€ routes/                      # Endpoint definitions
β”‚   β”œβ”€β”€ index.ts
β”‚   β”œβ”€β”€ check.routes.ts
β”‚   └── nodes.routes.ts
β”œβ”€β”€ controllers/                 # Request/response handling
β”‚   β”œβ”€β”€ check.controller.ts
β”‚   └── nodes.controller.ts
β”œβ”€β”€ usecase/                     # Business logic
β”‚   β”œβ”€β”€ CheckPing.usecase.ts
β”‚   β”œβ”€β”€ CheckHttp.usecase.ts
β”‚   β”œβ”€β”€ CheckTcp.usecase.ts
β”‚   β”œβ”€β”€ Result.usecase.ts
β”‚   └── nodes/
β”‚       β”œβ”€β”€ fetchNodes.usecase.ts
β”‚       └── getNodes.usecase.ts
β”œβ”€β”€ services/                    # Check-Host.net HTTP calls
β”‚   β”œβ”€β”€ checks.service.ts
β”‚   β”œβ”€β”€ check-result.service.ts
β”‚   └── fetchNodes.service.ts
β”œβ”€β”€ util/
β”‚   β”œβ”€β”€ ApiResponse.ts           # Success/failure envelope
β”‚   β”œβ”€β”€ nodeCache.ts             # In-memory node cache
β”‚   └── mapper.ts                # Raw β†’ normalized result mappers
β”œβ”€β”€ middlewares/
β”‚   └── errorHandler.ts          # Centralized error handler
└── type/                        # Shared TypeScript types
    β”œβ”€β”€ GlobalType.ts
    └── NodeTypes.ts

Scripts

Script Description
npm run dev Start in watch mode with nodemon + ts-node.
npm run build Compile TypeScript to dist/.
npm start Run the compiled server from dist/.
npm run lint Lint the src/ folder with ESLint.

Roadmap

  • DNS check endpoint (/check/dns) β€” the underlying route already exists in the Check-Host client.
  • Persistent node cache / periodic auto-refresh.
  • Request validation middleware (e.g. zod).
  • Automated tests and CI.
  • API documentation via OpenAPI/Swagger.

License

Released under the MIT License. See LICENSE for details.


Built with ❀️ using TypeScript & Express β€” powered by Check-Host.net

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages