Blog

Blog

How to monitor a REST API

How to monitor API endpoints properly: assert on the response body, not just the status code, handle authentication and multi-step flows, and set a latency budget.

  • api monitoring
  • rest
  • json

What is different about monitoring an API

An API has no page to look at, so "does it load" is not enough. The contract you care about is the shape and content of the response: the right status code, the right fields, the right values, and a response fast enough to be usable. Monitoring an API well means asserting against that contract, not just checking that the server accepted the connection.

APIs are also composed. A single endpoint might depend on a database, a cache, and two downstream services, so an API check is often the earliest place a partial outage becomes visible.

Assert on the response, not just the status

Start with the status code, but treat it as a range rather than a single number where that matches your API — some endpoints legitimately return 201, 202, or 204. Then assert on the body. PageLantern API checks send custom methods, headers, and request bodies and can assert status-code ranges, JSONPath expressions, and JSON Schema validation, so you can require that a specific field exists and holds an expected value rather than trusting a 200.

A good assertion is specific enough to catch a real regression but not so brittle that every harmless change breaks it. Checking that "status" equals "ok" and that an array is non-empty is usually more durable than pinning every field in a large payload.

Authentication and multi-step flows

Most real endpoints require a token. For flows that need a fresh credential, a multi-step check can call a login or token endpoint first, extract a value from that response, and pass it into the next request — for example authenticating and then calling a protected endpoint. PageLantern supports multi-step checks that chain requests and extract variables between them on paid plans, and can import operations from OpenAPI and Postman collections so you are not hand-building every monitor.

Keep monitoring credentials scoped and rotate them like any other secret. A monitor only needs enough access to exercise the endpoint, never production admin rights.

Set a latency budget

Latency is part of an API's contract. Decide what "too slow" means for each endpoint and assert on it, so a p95 that has crept from 200 ms to 2 seconds becomes an alert instead of a slow-burning complaint. Tie that budget back to your service objectives: if you promise a 300 ms response, your monitor should flag sustained breaches of it.

When a check does fail, the request and response detail — including a HAR export of the run — is what turns "the API is down" into a specific, reproducible bug report.

An API monitoring checklist

Monitor the endpoints your customers depend on, including at least one authenticated path. Assert on status-code ranges and on specific response fields, not just a 200. Add a latency threshold that reflects your target. Require consecutive failures before alerting so a single blip does not page anyone. Capture request and response detail for failed runs so triage starts with evidence.