Do you need a simple way to validate that an API endpoint is responsive, but you don't want to use curl?
There is a simple way to validate the endpoint with nc, producing an output that can be redirected to a logfile and parsed later:
URL=$1
PORT=$2
while true; do
RESULT=$(nc -vz $URL $PORT 2>&1)
DATE=$(date)
echo $DATE $RESULT
sleep 1
done
You can all this script with the API URL as first parameter, and API port as the second.
netcat will be accessing to that endpoint and will report the results, detecting when the API is down. We also can output the date to have a reference when failures are detected.
The produced output will be something like:
vie jun 26 08:19:28 UTC 2020 Ncat: Version 7.70 ( https://nmap.org/ncat ) Ncat: Connected to 192.168.111.3:6443. Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
vie jun 26 08:19:29 UTC 2020 Ncat: Version 7.70 ( https://nmap.org/ncat ) Ncat: Connected to 192.168.111.3:6443. Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
vie jun 26 08:19:30 UTC 2020 Ncat: Version 7.70 ( https://nmap.org/ncat ) Ncat: Connected to 192.168.111.3:6443. Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
vie jun 26 08:19:44 UTC 2020 Ncat: Version 7.70 ( https://nmap.org/ncat ) Ncat: Connection refused.
You can simply watch it on your terminal, or redirect the output to a file or to some log processing system for later consumption.
There is a simple way to validate the endpoint with nc, producing an output that can be redirected to a logfile and parsed later:
URL=$1
PORT=$2
while true; do
RESULT=$(nc -vz $URL $PORT 2>&1)
DATE=$(date)
echo $DATE $RESULT
sleep 1
done
You can all this script with the API URL as first parameter, and API port as the second.
netcat will be accessing to that endpoint and will report the results, detecting when the API is down. We also can output the date to have a reference when failures are detected.
The produced output will be something like:
vie jun 26 08:19:28 UTC 2020 Ncat: Version 7.70 ( https://nmap.org/ncat ) Ncat: Connected to 192.168.111.3:6443. Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
vie jun 26 08:19:29 UTC 2020 Ncat: Version 7.70 ( https://nmap.org/ncat ) Ncat: Connected to 192.168.111.3:6443. Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
vie jun 26 08:19:30 UTC 2020 Ncat: Version 7.70 ( https://nmap.org/ncat ) Ncat: Connected to 192.168.111.3:6443. Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
vie jun 26 08:19:44 UTC 2020 Ncat: Version 7.70 ( https://nmap.org/ncat ) Ncat: Connection refused.
You can simply watch it on your terminal, or redirect the output to a file or to some log processing system for later consumption.
Testing an API endpoint involves sending different types of requests and verifying the responses received to ensure that the API is functioning as expected. Proper testing can help detect and resolve issues such as incorrect data, broken functionality, and security vulnerabilities, leading to improved app performance and user experience. Here you find more information on what is an API endpoint. Thanks
ReplyDelete