How to use JSON/text APIs
Using JSON/text APIs from a webpage is as simple as:
fetch("https://cannicideapi.glitch.me/someapiurl")
.then(res => res.text()) //or res.json() for JSON
.then(body => {
//Content is contained in body variable
console.log(body);
});
If you are using a JSON/text API from a NodeJS environment, the usage is the same,
but you will need to import the npm module 'node-fetch' like so:
require("node-fetch");
How to use image/video/audio APIs
Most image/video/audio APIs directly return their respective image/video/audio content. Therefore, these APIs can be used directly where you need them. Here is an example using our Minecraft avatar API:
<img src="https://cannicideapi.glitch.me/mc/avatar/Cannicide" />
How to use libraries and script APIs
Libraries must be imported into your project, which will look different depending on your javascript environment. In regular JS found on webpages, web-compatible libraries can be imported like so:
<script src="https://cannicideapi.glitch.me/lib/somelibraryurl"></script>
That snippet should be included either at the top of your webpage in the HEAD tags, or at the bottom of your webpage
beneath your BODY tags, depending on which location the library requires (see the library's documentation for the location).In NodeJS, node-compatible library modules can be imported like so:
require("./locallibrarylocation")
Using NodeJS library modules requires downloading
those libraries first, or downloading a library package that includes the needed libraries. After downloading the library,
import it by replacing the arguments of the require statement above with the library's file location on your system. Do not include
the '.js' extension in the file location.