Java API
Primitive Java API work.
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://k-pop.p.rapidapi.com/idols?q=Jungkook&by=Stage%20Name"))
.header("X-RapidAPI-Key", "df17610e35msh51d75ac58fb44f9p14c5f0jsn7d95a150e08b")
.header("X-RapidAPI-Host", "k-pop.p.rapidapi.com")
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://car-api2.p.rapidapi.com/api/models?sort=id&direction=asc"))
.header("X-RapidAPI-Key", "df17610e35msh51d75ac58fb44f9p14c5f0jsn7d95a150e08b")
.header("X-RapidAPI-Host", "car-api2.p.rapidapi.com")
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
Purpose of API
An API allows for a website to make use of the data already out there on the internet. This can enrich a website without having to put together all of the data from scratch.
Backend Implementation
To be able to smoothly integrate an API with a nice frontend display of data, a backend is needed to interpret the JSON.
Additionally, many APIs, especially on sources like RAPIDAPI, limit the number of calls. A backend allows for a workaround of this, so data can be stored and refreshed once per day (instead of once per page load).