Skip to content

feat(admin): JSON query API beyond bulk export (P2-04 / 26.14)#17

Merged
CryptoJones merged 1 commit into
mainfrom
sprint/26.14-query-api
May 27, 2026
Merged

feat(admin): JSON query API beyond bulk export (P2-04 / 26.14)#17
CryptoJones merged 1 commit into
mainfrom
sprint/26.14-query-api

Conversation

@CryptoJones
Copy link
Copy Markdown
Owner

Summary

Adds `GET /api/v1/hosts` (filterable + paginated) and `GET /api/v1/hosts/{ip}` alongside the existing `/export.json` bulk endpoint. Downstream consumers (CMDB ingest, ticketing webhooks, monitoring) no longer have to pull the whole inventory and grep.

```bash

every linux host on 10.0.0.0/24 with SSH open

curl 'http://localhost:9090/api/v1/hosts?subnet=10.0.0.0/24&device_type=linux-host&port=22'

all printers, page 2

curl 'http://localhost:9090/api/v1/hosts?device_type=printer&limit=50&offset=50'

single host detail with its ports

curl 'http://localhost:9090/api/v1/hosts/10.0.0.42'
```

Filter dimensions (all optional, AND together)

Param Behaviour
`vendor` exact match
`device_type` exact match
`hostname` case-insensitive substring
`subnet` CIDR membership
`port` host must have that TCP port open
`limit` default 100, capped at 1000
`offset` default 0

Test plan

  • `go test -race ./internal/admin/...` — 13 new tests covering every filter dimension, combined filters, pagination edges, 400 on bad input, 404 on unknown host
  • `golangci-lint run ./...` → 0 issues
  • No new external deps

🤖 Generated with Claude Code

Adds /api/v1/hosts (filterable + paginated) and /api/v1/hosts/{ip}
alongside the existing /export.json bulk endpoint. Operators piping
inventory into a CMDB / ticketing webhook / monitoring stack no
longer have to download the full snapshot and grep.

GET /api/v1/hosts query params (all optional, AND together):
  vendor       — exact match
  device_type  — exact match
  hostname     — case-insensitive substring
  subnet       — CIDR membership
  port         — integer; host must have that TCP port open
  limit        — page size (default 100, max 1000)
  offset       — zero-based

Response envelope keeps `total` as the pre-pagination count so
consumers can drive their own page-cursor UI.

GET /api/v1/hosts/{ip} returns {host, ports[]} in one round-trip so
clients don't need a second request for the ports table.

Errors are JSON {"error": "..."} with proper 4xx/5xx codes. 13 new
tests covering every filter dimension, combined filters, pagination
edges (incl. offset past total), invalid input → 400, unknown host
→ 404.

internal/admin/api.go is separated from the HTML-template handlers
in handlers.go so the two concerns can evolve independently.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@CryptoJones CryptoJones merged commit ed6f3d4 into main May 27, 2026
@CryptoJones CryptoJones deleted the sprint/26.14-query-api branch May 27, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant