Sign inSign up

madebyai/device-detector

By madebyai

Updated about 1 month ago

This is a lightweight, high-performance API service wrapping the node-device-detector

Image
API management
0

48

madebyai/device-detector repository overview

This is a lightweight, high-performance API service wrapping the node-device-detector package, using Node.js and Fastify, encapsulated within a Docker Image.

Features

  • High-Performance: Uses Fastify which is significantly faster than Express.
  • Dockerized: Runs as a lightweight node:26-alpine Docker container.
  • Flexible UA parsing: Can parse the User-Agent from either the HTTP headers or the ua query parameter.
  • Client Hints: Also parses client-hint headers if provided.
  • Safe defaults: Returns an empty response structure with HTTP 200 OK if the User-Agent is empty or missing.

Prerequisites

  • Docker

Running the Container

Run the newly built Docker image on port 3000:

docker pull madebyai/device-detector:latest
docker run -d -p 3000:3000 --name device-detector madebyai/device-detector:latest

The API service will now be accessible at http://localhost:3000.

API Usage

The service exposes a single endpoint at GET /detect.

1. Detect from Header (Standard usage)

Request:

curl -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" http://localhost:3000/detect

Response:

{
  "os": {
    "name": "Windows",
    "version": "10",
    "platform": "x64",
    "short_name": "WIN"
  },
  "client": {
    "type": "browser",
    "name": "Chrome",
    "version": "115.0.0.0",
    "engine": "Blink",
    "engine_version": "",
    "short_name": "CH"
  },
  "device": {
    "type": "desktop",
    "brand": "",
    "model": ""
  }
}
2. Detect from Query Parameter

You can pass the User-Agent via the ua query parameter. It must be URL-encoded.

Request:

curl "http://localhost:3000/detect?ua=Mozilla%2F5.0+%28iPhone%3B+CPU+iPhone+OS+16_5+like+Mac+OS+X%29+AppleWebKit%2F605.1.15+%28KHTML%2C+like+Gecko%29+Version%2F16.5+Mobile%2F15E148+Safari%2F604.1"

Response:

{
  "os": {
    "name": "iOS",
    "version": "16.5",
    "platform": "",
    "short_name": "IOS"
  },
  "client": {
    "type": "browser",
    "name": "Mobile Safari",
    "version": "16.5",
    "engine": "WebKit",
    "engine_version": "605.1.15",
    "short_name": "MF"
  },
  "device": {
    "type": "smartphone",
    "brand": "Apple",
    "model": "iPhone"
  }
}
3. Missing or Empty User-Agent

If no User-Agent is provided, the API will still return a 200 OK status with default empty values.

Request:

curl http://localhost:3000/detect

Response:

{
  "os": {
    "name": "",
    "version": "",
    "platform": "",
    "short_name": ""
  },
  "client": {
    "type": "",
    "name": "",
    "version": "",
    "engine": "",
    "engine_version": "",
    "short_name": ""
  },
  "device": {
    "type": "",
    "brand": "",
    "model": ""
  }
}

Dependencies

Tag summary

Content type

Image

Digest

sha256:e0ddc9b41

Size

66.7 MB

Last updated

about 1 month ago

docker pull madebyai/device-detector