Testing with Sample responses
Each API version has a Design preview URL. It answers requests from the version's saved document with Sample responses, so you can try an API before anything is built behind it. API Studio > Test > Try it sends requests to it with the Simulated target.
Testing needs the API test permission.
The Design preview URL
The URL has this shape:
https://<your DataLug address>/t/<account short code>/preview/<api slug>/<version>/<operation path>
It uses the same address as the DataLug app. API Studio > Test > Try it and your own tools send requests to the same URL.
The Design preview URL never calls another system. Every answer comes from the saved document.
Create a test key
Every request needs a test key for the API.
- Open the API and open API Studio > Test > Try it.
- Under Test keys, enter a Key name and press Create key.
- Copy the key. It is shown once.
The list shows each key by name and prefix. Press Revoke to stop a key working. A key opens only the API it was created for.
Each API has a limit on active test keys, set by your administrator. When the limit is reached, revoke a key before you create another.
Send the key in one of these headers:
Authorization: Bearer <key>X-Api-Key: <key>
Send a request
- In API Studio > Test > Try it, pick an Operation. In API Studio > Design > Endpoints, Try it on a row opens API Studio > Test > Try it with that operation.
- Leave Target on Simulated.
- Enter the key in Test key.
- Fill in the parameters and the body. Both start from the operation's schema.
- Press Send.
The answer shows the status, the headers, the body and any validation problems. Copy as curl
copies the same request for a terminal, with the key written as $DATALUG_TEST_KEY.
How the answer is chosen
A valid request gets the operation's success response, with its declared status and media type. The body is:
- The named example, when the request sends
Prefer: example=<name>. - Otherwise the first example in the document.
- Otherwise a value built from the response schema. The same schema always gives the same value.
Errors
Errors use the problem details format (application/problem+json).
| Status | When |
|---|---|
| 400 | The path, query, headers or body do not match the operation. Each problem lists a JSON pointer. |
| 401 | The key is missing, wrong or revoked. |
| 404 | No operation matches the path. |
| 405 | The path exists but not for this method. The Allow header lists the methods. |
| 413 | The body is larger than the allowed size. |
| 415 | The body's media type is not one the operation accepts. |
| 428 | A PUT, PATCH or DELETE has no If-Match and the operation declares a 428 response. |
| 429 | Too many requests for this key. Retry-After gives the seconds to wait. |
Your administrator sets the body size and the request rate for each key.
For the reference docs of a version, see Reference docs.