API Examples

Get all of the code for this example on Dan's GitHub


JavaScript Navigator API

navigator.geolocation [?]

Your Location:

navigator.onLine [?]

This browser is --


Third Party APIs

Google Fonts API [?]

A free Google API to bring eclectic fonts to your website.

JSON Random User API [?]

Here is Raw JSON data for modeling a person (user) with lots of properties. You need to parse the JSON to make it readable for HTML, as below:

A random first name: --

JSON Open Weather API [?]

A Third Party API that needs an api key to work. I made weather.php that uses my (hidden) API key to pass a query on to openweathermap.org for raw JSON that has to be interpreted -- see the JS that uses fetch() to get and parse the data.

There are a few ways to hide API keys so they can't be accessed by anyone with an internet connection. I put mine in a directory outside of the web document root, so the internet can't see it, but my weather.php file on the server still can.

Right now in --, the temperature is --.

RESTful Hypermedia API [?]

When a user clicks on this button, make an AJAX request to hypermedia_response.html, and replace the entire button with the HTML response: