Check if a page or post url is public or exits
I am new to wordpress and I wanted to know if there is a way to check if a post or page URL in wordpress is public or the url exists. I came across
wp_remote_head(url) and to check for the response code. Is there a better or correct way to check this?