15
how does the status monitoring website work under the hood?
(programming.dev)
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Follow the wormhole through a path of communities !webdev@programming.dev
Simple, do a
GET
orHEAD
HTTP request to the monitored website with a 3 second timeout. If you get a200
response code then you can assume the website is online and okay.Why HEAD? Because:
Using
HEAD
instead ofGET
will make it so your code doesn't have to actually download your frontpage to get the status. This will speed things up and reduce bandwidth usage.Note: webservers may also return response codes for redirects, like
301
or308
and and this case you usually do a follow up request to the URL the server pointed you at in order to check if it returns200
. Some HTTP libraries have built in ways to handling this and with a simple boolean they'll follow the redirect for you.