API Usage
There are currently 5 different API endpoints used by the front-end of the application.
These can all be found in client/src/hooks.
They all use axios for the requests, and each implements a different function.
Helper functions for transforming data and the global types used can be found in client/utils.
API Hooks
useFetchIPData
This hook provides the user’s query (IP or domain name) as a payload to the backend.
It performs a POST request to the backend to measure the given NTP server. If the query is a domain name, the result includes all NTP servers measured from that domain name. If it’s an IP, only that specific NTP server is measured.
It parses the JSON received using the method
transformJSONDataToNTPData.It returns a 5-tuple:
Return value
Description
dataAn array of NTP results
loadingbooleanindicating if the measurement is ongoingerrorError object if one occurred
httpStatusThe HTTP status of the request
fetchDataA function to initiate the POST request
useFetchHistoricalIPData
This hook fetches data over a specific period for a given server.
It performs a GET request to the backend. The server can be either an IP or domain name. Start and end times must be in ISO8601 format.
It also uses
transformJSONDataToNTPData.It returns a 4-tuple:
Return value
Description
dataAn array of NTP results
loadingbooleanindicating if the fetch is ongoingerrorError object if one occurred
fetchDataA function to initiate the GET request
triggerRipeMeasurement
This hook sends a trigger to start a RIPE measurement.
It performs a POST request to the backend with the server as payload. The backend responds with the measurement ID and the vantage point’s IP.
It returns a 4-tuple:
Return value
Description
dataThe response as a
RIPERespobjectloadingbooleanindicating if the trigger is being processederrorError object if one occurred
fetchDataA function to initiate the POST request
useFetchRipeData
This hook fetches RIPE measurement data via polling.
RIPE sends results in parts, so polling is used to retrieve updates. If the RIPE measurement isn’t ready, the hook handles HTTP 405 and retries after a delay. The polling stops if: - An error occurs - Measurement completes - It times out - A new measurement begins
It returns a 3-tuple:
Return value
Description
resultAn array of RIPE results
statusA status string:
"pending" | "partial_results" | "complete" | "timeout" | "error"errorError object if one occurred
useIpInfo
This hook fetches geolocation data for an IP without contacting the backend.
It uses
ip-apito retrieve coordinates and country code. Used for NTP servers and the vantage point.The result is stored in an
IpInfoDataobject:coordinates: a tuple[number, number]country_code: astring
Note: If the IP is private,
coordinateswill be[undefined, undefined].It returns a 5-tuple:
Return value
Description
dataGeolocation data as
IpInfoDataloadingbooleanindicating if the fetch is ongoingerrorError object if one occurred
fetchDataA function to initiate the GET request
clearIPA function to reset the internal state of
data