Skip to content

[Feature] Added API endpoints to list, get and get the latest results#1983

Merged
alexjustesen merged 11 commits intomainfrom
api-list-and-read-results
Jan 13, 2025
Merged

[Feature] Added API endpoints to list, get and get the latest results#1983
alexjustesen merged 11 commits intomainfrom
api-list-and-read-results

Conversation

@alexjustesen
Copy link
Copy Markdown
Owner

@alexjustesen alexjustesen commented Jan 13, 2025

📃 Description

This PR implements /results API endpoints, you can list all results, get a specific result or get the latest result. This PR also introduces an "API Tokens" page for the user to manage their tokens.

curl localhost/api/v1/results
   -H "Accept: application/json"
   -H "Authorization: Bearer yourtokengoeshere"

⚙️ Interacting with the API

When listing results you can sort and filter the response using the following criteria and fields.

🔑 Authentication

A "Bearer Token" is required to authenticate into the API, you can generate tokens for your user account on /admin/api-tokens.

🔎 Filtering

You can filter the results response by the fields: ping, download, upload, healthy, status, scheduled and created_at.
created_at has been aliased to start_at and end_at to enable date range filtering in #1998.

Example: filter for dates in a range

curl localhost/api/v1/results?filter[start_at]>=2024-01-01&filter[end_at]<=2024-12-31
   -H "Accept: application/json"
   -H "Authorization: Bearer yourtokengoeshere"

Example: filter for only unhealthy results

curl localhost/api/v1/results?filter[healthy]=false
   -H "Accept: application/json"
   -H "Authorization: Bearer yourtokengoeshere"

Example: filter for "failed" and "skipped" results

curl localhost/api/v1/results?filter[status]=failed,skipped
   -H "Accept: application/json"
   -H "Authorization: Bearer yourtokengoeshere"

Package docs: https://spatie.be/docs/laravel-query-builder/v5/features/filtering

📈 Sorting

You can sort the results response by the fields: ping, download, upload, created_at or updated_at. Sorting is ascending by default and can be reversed by adding a hyphen (-) to the start of the property name.

curl localhost/api/v1/results?sort=-created_at
   -H "Accept: application/json"
   -H "Authorization: Bearer yourtokengoeshere"

Package docs: https://spatie.be/docs/laravel-query-builder/v5/features/sorting

🪵 Changelog

➕ Added

  • api/v1/results to list API results
  • api/v1/results/latest to get the latest result
  • api/v1/results/id to get a specific result

✏️ Changed

  • moved response for api/healthcheck to api.php route file instead of a controller
  • marked /api/healthcheck as deprecated
  • marked /api/speedtest/latest as deprecated

📖 Data Dictionary

The data structure returned mimic the results table but includes the addition of download_bits, upload_bits, download_bits_human and upload_bits_human.

Example:

{
  "data": {
    "id": 1009,
    "service": "ookla",
    "ping": 7.448,
    "download": 167270969,
    "upload": 115884569,
    "download_bits": 1338167752,
    "upload_bits": 927076552,
    "download_bits_human": "1.34 Gbps",
    "upload_bits_human": "927.08 Mbps",
    "benchmarks": null,
    "healthy": null,
    "status": "completed",
    "scheduled": true,
    "comments": null,
    "data": {
    },
    "created_at": "2025-01-13 16:37:00",
    "updated_at": "2025-01-13 16:37:17"
  }
}

🤔 Potential Questions...

  • Can I create, update or delete results using the API? No, not at this time its read-only.

@alexjustesen alexjustesen added the feature New feature or request label Jan 13, 2025
@alexjustesen alexjustesen self-assigned this Jan 13, 2025
@alexjustesen alexjustesen merged commit cf13ecb into main Jan 13, 2025
@alexjustesen alexjustesen deleted the api-list-and-read-results branch January 13, 2025 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add data to 'latest' [GET] endpoint.

1 participant