Skip to content

Commit 2251e02

Browse files
committed
Merge branch 'guolau/restore-cli-missing-pages' of github.com:checkly/docs into guolau/restore-cli-missing-pages
2 parents 4df8a85 + 00ec13b commit 2251e02

23 files changed

Lines changed: 159 additions & 156 deletions

File tree

api-reference/openapi.json

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

constructs/api-check.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,12 @@ You must provide either `entrypoint` or `content`, but not both.
423423
To define `assertions` for the `request` of an `ApiCheck` you should use the `AssertionBuilder`. The following sources are available for API check assertions:
424424

425425
- `statusCode()`: Assert the HTTP status code for the HTTP request, e.g. 200 or 404
426-
- `jsonBody(property?)`: Assert the JSON response body. The property argument accepts a [JSON path expression](/docs/api-checks/assertions/#json-responses-with-json-path)
426+
- `jsonBody(property?)`: Assert the JSON response body. The property argument accepts a [JSON path expression](/detect/assertions/#json-responses-with-json-path)
427427
- `textBody()`: Assert the body as raw text
428428
- `headers(propery?, regex?)`: Assert a set of response headers, takes the header name as the property argument and a regex to tease out a string from the header value
429429
- `responseTime()`: Assert the total response time of the HTTP request
430430

431-
Learn more in our docs on [Assertions](/docs/api-checks/assertions/).
431+
Learn more in our docs on [Assertions](/detect/assertions).
432432

433433
**Assertion Examples**
434434

constructs/dns-monitor.mdx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,6 @@ new DnsMonitor("dns-monitor", {
125125
| `protocol` | `DnsProtocol` || `UDP` | Protocol to use: UDP or TCP |
126126
| `assertions` | `DnsAssertion[]` || `[]` | Response assertions using `DnsAssertionBuilder` |
127127

128-
Define assertions using the `DnsAssertionBuilder` to validate DNS responses:
129-
130-
```ts
131-
DnsAssertionBuilder.responseTime().lessThan(1000)
132-
DnsAssertionBuilder.textAnswer().contains("192.168.1.1")
133-
DnsAssertionBuilder.jsonAnswer("$.Answer[0].data").equals("93.184.216.34")
134-
```
135-
136-
Learn more in [Assertions](/detect/uptime-monitoring/dns-monitors/configuration#assertions).
137128
</ResponseField>
138129

139130
<ResponseField name="degradedResponseTime" type="number" default="500">
@@ -180,7 +171,7 @@ To define `assertions` for the `request` of an `DnsMonitor` you should use the `
180171
- `responseTime()`: Assert the total response time of the DNS request in milliseconds. Use this to set thresholds for failed lookups
181172
- `responseCode()`: By default, DNS monitors pass when the return code is NOERROR and fail on error codes (FORMERR, SERVFAIL, NXDOMAIN, etc.). You can override this behavior by defining a custom return code assertion
182173
- `textAnswer()`: The raw DNS response as plain text. Use this to check for specific strings in the response
183-
- `jsonAnswer(property?)`: The DNS response in JSON format. This allows you to target specific fields using JSON path assertions. The response structure varies by record type. [Learn more about using JSON path](/docs/api-checks/assertions/#json-responses-with-json-path).
174+
- `jsonAnswer(property?)`: The DNS response in JSON format. This allows you to target specific fields using JSON path assertions. The response structure varies by record type. [Learn more about using JSON path](/detect/assertions/#json-responses-with-json-path).
184175

185176
Here are some examples:
186177

@@ -208,7 +199,7 @@ DnsAssertionBuilder.jsonAnswer('$.Answer.length').equals(4)
208199
{ source: 'JSON_ANSWER', property: '$.Answer.length', comparison: 'EQUALS', target: '4' }
209200
```
210201

211-
Learn more in our docs on [Assertions](/docs/api-checks/assertions/).
202+
Learn more in our docs on [Assertions](/detect/assertions).
212203

213204
### General Monitor Options
214205

constructs/tcp-monitor.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ TcpAssertionBuilder.responseData().contains('ping')
274274
{ source: 'RESPONSE_DATA', comparison: 'CONTAINS', target: 'ping' }
275275
```
276276

277-
Learn more in our docs on [Assertions](/docs/api-checks/assertions/).
277+
Learn more in our docs on [Assertions](/detect/assertions).
278278

279279
### General Monitor Options
280280

constructs/url-monitor.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ UrlAssertionBuilder.statusCode().lessThan(300)
253253
{ source: 'STATUS_CODE', comparison: 'lessThan', target: '300' }
254254
```
255255

256-
Learn more in our docs on [Assertions](/docs/api-checks/assertions/).
256+
Learn more in our docs on [Assertions](/detect/assertions).
257257

258258
### General Monitor Options
259259

detect/synthetic-monitoring/api-checks/assertions.mdx renamed to detect/assertions.mdx

Lines changed: 48 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,46 @@
11
---
2-
title: 'Writing assertions for API checks'
3-
description: 'Writing assertions for API checks'
2+
title: 'Defining Assertions'
3+
description: 'Add assertions to validate your check results'
44
sidebarTitle: 'Assertions'
55
---
66

7-
8-
9-
The response of an API request can be checked for correctness and timeliness by using assertions on the response data. Assertions are flexible statements that combine preset modifiers with custom values to meet the needs of a broad set of use cases.
7+
Uptime monitors and API checks allow you to define assertions to validate a response and check its data for correctness.
108

119
## How assertions work
1210

13-
Assertions are statements you create that check one aspect of the HTTP response. You can create multiple assertions for one check that assert various aspects of a response, for example:
11+
Assertions let you validate specific parts of a check's response. For example:
1412

15-
- HTTP response status equals 200.
16-
- HTTP response body equals the text "success".
17-
- HTTP response time is lower than 2000 milliseconds.
18-
- HTTP response header "X-Custom-Header" equals "SomeValue".
19-
- HTTP response JSON object has a key called "accountBalance" with a value greater than 9999
13+
- **URL monitor**: HTTP response status equals 200.
14+
- **TCP monitor**: Response contains expected string (e.g. OK).
15+
- **DNS monitor**: Resolved IP equals 93.184.216.34.
16+
- **API check**: HTTP response header "X-Custom-Header" equals "SomeValue".
17+
18+
### Sources
2019

2120
In each assertion, a **source** is connected to a **comparison** and a **target**.
2221

2322
![api monitoring assertions example 1](/images/docs/images/api-checks/assertions-1.png)
2423

25-
In some cases a **property** is added, for example when asserting headers or JSON response bodies.
24+
In some cases a [property](#property) is added, for example when asserting API check headers or JSON response bodies.
2625

2726
![api monitoring assertions example 2](/images/docs/images/api-checks/assertions-2.png)
2827

2928
Assertions are executed from top to bottom. If one assertion fails, the full check is considered as failed.
3029

31-
## Source
32-
33-
On each API check assertion, the following sources are available:
30+
Supported assertion sources vary by monitor type. Refer to the documentation of the specific monitor (API, DNS, TCP, etc.) to see which sources are available.
3431

35-
- **Status code:** The HTTP response status, parsed as an integer.
36-
- **JSON body:** The response body parsed as a JSON object.
37-
- **Text body:** The response body as plain text.
38-
- **Headers:** The response headers as an array of key/value pairs.
39-
- **Response time:** The response time of the full API request in milliseconds, parsed as an integer value.
32+
### Property
4033

41-
## Property
34+
The property field is a free-form text input that lets you point to a specific part of the data you want to validate. It’s available for the following types of assertion [sources](#sources):
4235

43-
The property field is a free form text field used to identify the name of a header, the part of a JSON object using JSON path or part of a text body.
36+
- **JSON response bodies**: Use a JSON path expression in the form of dot-separated strings to
37+
target nested properties in an object, i.e. `$.product.size` or an item in an array, i.e. `$.[1].key`. [Learn more](#json-responses-with-json-path).
4438

45-
- With **JSON response bodies**, the property field accepts **JSON path** expressions in the form of dot-separated strings to
46-
target nested properties in an object, i.e. `$.product.size` or an item in an array, i.e. `$.[1].key`
39+
- **Text response bodies**: Provide a regular expression with a capture group to pick out parts,
40+
i.e. `<!doctype (.{4})` would grab the word `html` from a body return `<doctype html>`. [Learn more](#text-body-assertions-with-regular-expressions).
4741

48-
- With **text response bodies**, the property field accepts a **regular expression** with a capture group to pick out parts,
49-
i.e. `<!doctype (.{4})` would grab the word `html` from a body return `<doctype html>`
50-
51-
- With **headers**, you provide the header you want to assert in the property field, i.e. `Content-Type`. You can even add a
52-
regular expression after that to tease out a specific part of the header.
53-
54-
Read more about asserting JSON response bodies below.
42+
- **API check headers**: Enter the header name you want to assert on i.e. `Content-Type`. You can even add a
43+
regular expression after that to tease out a specific part of the header. [Learn more](#using-regular-expressions).
5544

5645
## Comparison
5746

@@ -75,19 +64,14 @@ Response time is empty? JSON Object is less than? We block out the comparisons w
7564

7665
The target field is a free form text field that determines the desired outcome of your assertion.
7766

78-
7967
## JSON responses with JSON path
8068

81-
You can use **JSON path** to specify which field of a JSON response body should be asserted. JSON path is a query language
69+
For monitors that support JSON body assertions, you can use **JSON path** to specify which field of a JSON response body should be asserted. JSON path is a query language
8270
similar to Xpath for XML, but in general a lot more intuitive and simpler to use.
8371

84-
> For Checkly to be able to parse the JSON body, the `Content-Type` header of the response should be set to `application/json`.
85-
8672
### JSON path primer
8773

88-
JSON path only uses a handful of operators in its queries. Not all of them are useful in the context of assertions.
89-
Here is an adapted set of examples based on [Stefan Goessner's 2007 introduction post](http://goessner.net/articles/JsonPath/).
90-
74+
The following JSONPath operators are available:
9175

9276
JSONPath | Description
9377
-----------------|------------
@@ -153,7 +137,6 @@ JSONPath | Description
153137
`$.store..price` | The price of everything in the store
154138
`$.store.book.length` | The length of the book array
155139
`$..book[2]` | The third book
156-
`$..book[(@.length-1)]` | The last book via script subscript
157140
`$..book[-1:]` | The last book via slice
158141
`$..book[0,1]` | The first two books via subscript union
159142
`$..book[:2]` | The first two books via subscript array slice.
@@ -163,8 +146,9 @@ JSONPath | Description
163146
`$..book[?(@.price<30 && @.category=="fiction")]` | Filter all fiction books cheaper than 30
164147
`$..*` | All members of JSON structure
165148

166-
Use this [online editor to play around](https://jsonpath.com/), or look at the examples below. We use this [jsonpath NPM
167-
module](https://github.com/dchester/jsonpath) under the hood.
149+
Use this [online editor](https://jsonpath.com/) to try out your own JSONPath expressions.
150+
151+
For a full description of the syntax and semantics, see [RFC 9535](https://datatracker.ietf.org/doc/rfc9535/). In addition to the RFC-defined syntax, we support a few convenience extensions (for example, `.length`) to make common assertions easier to write.
168152

169153
### Asserting basic types
170154

@@ -218,23 +202,26 @@ Regular expressions give you the power to extract specific parts of text from a
218202
You can use regular expressions with two assertions sources:
219203

220204
1. **Text body:** Use the property field to add your regex.
221-
2. **Headers:** First select the header you are interested in the property field, then click "add regex".
205+
2. **API check headers:** First select the header you are interested in the property field, then click "add regex".
222206

223-
Under the hood, we use the stock Javascript regular expressions implementation. Specifically, we use the [.match()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
224-
method. We *do not use the `/g` modifier* and return the first matched group the expression finds.
207+
We *do not use the `/g` modifier* and return the first matched group the expression finds.
225208

226-
Sounds more complicated than it is. Here is an example:
209+
Here is an example input:
210+
211+
```
212+
The quick brown fox jumps over the lazy dog. It barked.
213+
```
214+
215+
And the following regular expression:
227216

228-
```javascript
229-
const paragraph = 'The quick brown fox jumps over the lazy dog. It barked.'
230-
const regex = /quick (.*) fox/
231-
const found = paragraph.match(regex)
232-
console.log(found)
233-
234-
// [ 'quick brown fox',
235-
// 'brown',
236-
// index: 4,
237-
// input: 'The quick brown fox jumps over the lazy dog. It barked.' ]
217+
```
218+
/quick (.*) fox/
219+
````
220+
221+
The assertion extracts:
222+
223+
```
224+
brown
238225
```
239226
240227
In the example above we return the string `brown` because it is the first capture group, the `(.*)` bit.
@@ -244,25 +231,18 @@ The first item `quick brown fox` is the full match, which we do not return.
244231
245232
### Text body assertions with regular expressions
246233
247-
If our API returns HTML, there might be a `lang="en"` attribute in the `<html>` element. We can capture the two character
248-
country/language code value of that attribute with the following expression.
234+
When a check returns a text-based response, you can use regular expressions to extract and assert on specific parts of the response body.
235+
236+
For example, an HTML document might include a `lang="en"` attribute on the `<html>` element. You can capture the two-character language code using the following regular expression:
249237
250238
![api monitoring use regular expression on text body](/images/docs/images/api-checks/assertions-10.png)
251239
252240
The expression `lang="(.{2})"` means 'grab any of the first two characters between `lang="` and the next `"`'. If we were
253241
sure there are only non-capital characters, we could tighten it up a bit with `lang="([a-z]*)"`.
254242
255-
### Header assertions with regular expressions
243+
### API check header assertions with regular expressions
256244
257-
We can use regular expressions with headers too. In this example, we check if the `max-age` property of a `Strict-Transport-Security`
258-
response header is above a `100000`
245+
We can use regular expressions with [API check headers](/detect/synthetic-monitoring/api-checks/configuration#headers) too. In this example, we check if the `max-age` property of a `Strict-Transport-Security`
246+
response header is above a `100000`.
259247
260248
![api monitoring use regular expression on http header](/images/docs/images/api-checks/assertions-11.png)
261-
262-
263-
264-
265-
266-
267-
268-

detect/synthetic-monitoring/api-checks/requests.mdx renamed to detect/synthetic-monitoring/api-checks/configuration.mdx

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
11
---
2-
title: 'Requests'
3-
description: 'Requests'
4-
sidebarTitle: 'Requests'
2+
title: 'Configuration'
3+
description: 'Configure your API checks to validate responses and ensure your endpoints behave as expected.'
4+
sidebarTitle: 'Configuration'
55
---
66

77
import GenericRuntimeVariablesTable from '/snippets/generic-runtime-variables-table.mdx';
88

9-
A full HTTP request is created by filling out the various parts of the HTTP request settings screen. Not all sections and fields
10-
are mandatory, only a name and URL are required to get going.
9+
While configuring up your API check, you can run the request and its assertions using the **Run request** button. This will run the API check on production infrastructure and help you debug any issues.
1110

12-
While building up your API check, you can run the request and its assertions using the **Run request** button. This will run the
13-
API checks on the production infrastructure and help you debug any issues.
11+
## Basic Setup
1412

15-
## Method & URL
13+
Start by specifying the endpoint you want to track.
1614

17-
An API check starts with creating an HTTP request including a HTTP verb (GET, POST, PUT, etc.) and a URL at the minimum.
15+
![api monitoring request configuration](/images/docs/images/api-checks/api-request-configuration.png)
1816

19-
![api monitoring http request](/images/docs/images/api-checks/http-request-method.png)
20-
21-
- Available methods are `GET, POST, PUT, HEAD, DELETE, PATCH`
22-
- URL's are checked for correctness and must start with either `http://` or `https://`
23-
24-
Checking the **"This request should fail"** checkbox allows you to treat HTTP error codes (4xx and 5xx) as correct responses. This comes in handy when testing 404 pages or 500 error handling.
25-
26-
When enabled:
27-
* ✅ Failed responses (4xx, 5xx) → check passes
28-
* ✅ Successful responses → check passes
29-
* ❌ Failed assertions → check fails
17+
- **URL**: The HTTP(S) URL to monitor (e.g. https://checklyhq.com). URL's are checked for correctness and must start with either `http://` or `https://`.
18+
- **Request methods**: Available methods are `GET, POST, PUT, HEAD, DELETE, PATCH`.
19+
- **IP family**: Defaults to IPv4.
20+
- **Skip SSL**: Skip SSL certificate validation.
21+
- **Follow redirects**: Automatically follow 30x redirects.
22+
- **This request should fail**: Treat HTTP error codes (4xx and 5xx) as passed. Please note that successful responses still pass. Only failed assertions will cause the check to fail.
3023

3124
## Body
3225

@@ -48,7 +41,6 @@ JSON bodies are commonly used with REST APIs.
4841

4942
### GraphQL
5043

51-
5244
This option also sets the `Content-Type` request header to `application/json`, but allows you to type GraphQL queries and
5345
format them as such, i.e.
5446

@@ -93,10 +85,8 @@ This section allows you to add query parameters to the request URL in a structur
9385
9486
## Basic authentication
9587

96-
To add [HTTP basic authentication parameters](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication) to your API
97-
request, use the username and password fields in the relevant section.
98-
99-
![api monitoring basic auth](/images/docs/images/api-checks/http-request-auth.png)
88+
Add [HTTP basic authentication parameters](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication) to your API
89+
request by entering a username and password in the Authentication tab.
10090

10191
## Accessing environment variables
10292

@@ -167,6 +157,28 @@ parses your spec and prompts you to make some decisions about which requests are
167157
- **Add a "group" tag:** Copy the name of you spec to a tag and add it to each imported request. This helps
168158
filtering and grouping related checks in the Checkly dashboard.
169159

160+
## Assertions
161+
162+
The response of an API request can be checked for correctness and timeliness by using assertions on the response data. This allows you to verify things such as:
163+
164+
- HTTP response status equals 200.
165+
- HTTP response body equals the text "success".
166+
- HTTP response time is lower than 2000 milliseconds.
167+
- HTTP response header "X-Custom-Header" equals "SomeValue".
168+
- HTTP response JSON object has a key called "accountBalance" with a value greater than 9999.
169+
170+
![api check assertions](/images/docs/images/api-checks/api-check-assertions.png)
171+
172+
On each API check assertion, the following sources are available:
173+
174+
- **Status code:** The HTTP response status, parsed as an integer.
175+
- **JSON body:** The response body parsed as a JSON object. To enable parsing, the Content-Type header of the response should be set to application/json.
176+
- **Text body:** The response body as plain text.
177+
- **Headers:** The response headers as an array of key/value pairs.
178+
- **Response time:** The response time of the full API request in milliseconds, parsed as an integer value.
179+
180+
For more details, see our documentation on [Assertions](/detect/assertions).
181+
170182
## Responses
171183

172184
In almost all cases, you have full access to the HTTP response for assertions. We also store the full response

detect/synthetic-monitoring/api-checks/overview.mdx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,14 @@ API checks perform comprehensive endpoint validation:
5959
API checks are ideal for testing both internal services and external API dependencies your application relies on.
6060
</Tip>
6161

62-
## Timeouts
62+
## Response Metrics
6363

64-
All API checks are capped at a timeout of **30 seconds**. With each request, we record the most relevant timing phases. This can help you troubleshoot slow responses, e.g. your DNS might be slow.
64+
With each request, we record the most relevant timing phases:
6565

66-
The timing phases correspond to the Node.js request library timing phases:
67-
68-
- `wait`: Duration of socket initialization
6966
- `dns`: Duration of DNS lookup
7067
- `tcp`: Duration of TCP connection
7168
- `firstByte`: Duration of HTTP server response
7269
- `download`: Duration of HTTP download
7370

74-
![api monitoring timing phases](/images/docs/images/api-checks/timing-phases.png)
75-
76-
<Note>
77-
## Interpreting the `wait` metric
78-
79-
The "wait" time is the time it takes for the underlying Node HTTP module to get a socket from the network layer.
80-
This time can vary quite a bit, usually it goes from 900 microseconds to some milliseconds. Most clients for API / webpage will have this lag too.
81-
82-
</Note>
71+
This can help you troubleshoot slow responses, e.g. your DNS might be slow.
8372

0 commit comments

Comments
 (0)