avatarMING

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2595

Abstract

f="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses">Client error responses</a> (<code>400</code><code>499</code>)</li><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses">Server error responses</a> (<code>500</code><code>599</code>)</li></ol><p id="5619">Secondly, <b>statusText</b> explains what's happening in this status code. Instead of returning 404 to the end user, saying ‘Not Found’ can be more understandable.</p><figure id="3b01"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*[email protected]"><figcaption>Code — Text Sample Table</figcaption></figure><p id="8d0c">Finally, <b>isUP</b> or <b>isDown</b> is based on whether the status code is 200, and it will respond with a boolean (true/false).</p><h1 id="c5b3">How to Setup Locally?</h1><p id="0f22">Setup and running the project is super easy, with just three steps.</p><div id="b574" class="link-block"> <a href="https://github.com/1998code/isitdownorjustme-API"> <div> <div> <h2>GitHub - 1998code/isitdownorjustme-API: An api for 'is it down or just me' monitor.</h2> <div><h3>An api for 'is it down or just me' monitor. Contribute to 1998code/isitdownorjustme-API development by creating an…</h3></div> <div><p>github.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*RaEwi5XUOeK5TL8B)"></div> </div> </div> </a> </div><p id="8b50">Firstly, clone <a href="https://github.com/1998code/isitdownorjustme-API">t</a>he repository via GitHub. a) If you are using the command line:</p><div id="a397"><pre>git <span class="hljs-built_in">clone</span> https://github.com/1998code/isitdownorjustme-API</pre></div><p id="b4fb">b) or GitHub Desktop:</p><figure id="2262"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*[email protected]"><figcaption>GitHub > Code (Green Button)</figcaption></figure><p id="0bac">Then, install the package with the command:</p><div id="4fb4"><pre>npm</pre></div><p id="0314">or</p><div id="b3de"><pre>yarn</pre></div><p id="e409">To start the development server, run the following:</p><div id="065e"><pre>npm run dev</pre></div><p id="f717">or</p><div id="f7af"><pre>yarn dev</pre></div><p id="c238">Cool! Visit <a href="http://localhost:3000/">http://localhost:3000</a>, and you will see a welcome message. That means everything is

Options

ready to use.</p><figure id="4241"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*[email protected]"><figcaption>Welcome Page</figcaption></figure><p id="3745">The API route is similar to the remote one:</p><div id="b365"><pre>http://localhost:3000/api/public?url=&lt;WEBSITE_URL></pre></div><h1 id="1658">Developer tips:</h1><p id="b57a">You can use various ways to GET the result.</p><p id="5c26">For the nodeJS application, you may use <code>fetch</code> or <code>axios.get</code></p><p id="d0aa">If you are making an application with Swift/SwiftUI, try <code>URLSession with DataTask</code>.</p><h1 id="9258">Finished! 🎉</h1><figure id="8b77"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*NOQjyXQl9HCqmPtq.png"><figcaption>Sample Response</figcaption></figure><h2 id="bc27">All Source Code is available on #Github too. Find it below:</h2><div id="ab93" class="link-block"> <a href="https://github.com/1998code/isitdownorjustme-API"> <div> <div> <h2>GitHub - 1998code/isitdownorjustme-API: An api for 'is it down or just me' monitor.</h2> <div><h3>An api for 'is it down or just me' monitor. Contribute to 1998code/isitdownorjustme-API development by creating an…</h3></div> <div><p>github.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*RaEwi5XUOeK5TL8B)"></div> </div> </div> </a> </div><h2 id="f635">Thanks for reading :)</h2><h2 id="ef4b">Follow and stay tuned to the latest technology.</h2><div id="7c54" class="link-block"> <a href="https://twitter.com/1998design"> <div> <div> <h2>Ming | 1998design</h2> <div><h3>Twitter Official Page</h3></div> <div><p>twitter.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*yI9fHK5t60W5VmJT)"></div> </div> </div> </a> </div><h2 id="be8b">Reference</h2><p id="c058"><a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwiB26Cxy7_8AhVphMYKHbldCP0QFnoECA0QAQ&amp;url=https%3A%2F%2Fdeveloper.mozilla.org%2Fen-US%2Fdocs%2FWeb%2FHTTP%2FStatus&amp;usg=AOvVaw2pSlgOW81Ahg7C8tS8pF0W">HTTP response status codes — MDN Web Docs — Mozilla</a></p></article></body>

How to: Use Website Monitor API

Via the serverless proxy and getting the website status in JSON format

Previously, we introduced one of the best web monitors on the iOS and iPadOS platforms. The API behind it is open-sourced, too, here’s how the thing works.

Website Monitor API

Tested Environment

  • NextJS 12 (React)
  • Vercel
  • macOS 13 (Other OS should be fine too)

How to Test Remotely?

Testing Website Monitor API is easy. Simply type in and access in the following pattern:

https://monitor-api.vercel.app/api/public?url={{URL}}

You can use any type of HTTP or HTTPS in the URL. For example: https://monitor-api.vercel.app/api/public?url=https://apple.com

And you will get a response in JSON format:

{
  "status": 200,
  "statusText": "OK",
  "isUP": true,
  "isDown": false
}

Explain

Firstly, status refers to HTTP response status codes, e.g.,

  1. Informational responses (100199)
  2. Successful responses (200299)
  3. Redirection messages (300399)
  4. Client error responses (400499)
  5. Server error responses (500599)

Secondly, statusText explains what's happening in this status code. Instead of returning 404 to the end user, saying ‘Not Found’ can be more understandable.

Code — Text Sample Table

Finally, isUP or isDown is based on whether the status code is 200, and it will respond with a boolean (true/false).

How to Setup Locally?

Setup and running the project is super easy, with just three steps.

Firstly, clone the repository via GitHub. a) If you are using the command line:

git clone https://github.com/1998code/isitdownorjustme-API

b) or GitHub Desktop:

GitHub > Code (Green Button)

Then, install the package with the command:

npm

or

yarn

To start the development server, run the following:

npm run dev

or

yarn dev

Cool! Visit http://localhost:3000, and you will see a welcome message. That means everything is ready to use.

Welcome Page

The API route is similar to the remote one:

http://localhost:3000/api/public?url=<WEBSITE_URL>

Developer tips:

You can use various ways to GET the result.

For the nodeJS application, you may use fetch or axios.get

If you are making an application with Swift/SwiftUI, try URLSession with DataTask.

Finished! 🎉

Sample Response

All Source Code is available on #Github too. Find it below:

Thanks for reading :)

Follow and stay tuned to the latest technology.

Reference

HTTP response status codes — MDN Web Docs — Mozilla

Website Monitor Api
Http Status Code
Nextjs
Nodejs
Json
Recommended from ReadMedium