Ostatnio poszukując jakiegoś ciekawego api znalazłem SWAPI czyli Star Wars API. Trzeba przyznać że ilość zgromadzonych w bazie informacji jest wręcz przeogromna. Zobaczmy kilka przykładów:
function findPeople(str) {
fetch("https://swapi.dev/api/people/?search=" + str)
.then((response) => response.json())
.then((data) => console.log(data));
}
Rezultat w JSON:
{
"count":1,
"next":null,
"previous":null,
"results":[
{
"name":"Boba Fett",
"height":"183",
"mass":"78.2",
"hair_color":"black",
"skin_color":"fair",
"eye_color":"brown",
"birth_year":"31.5BBY",
"gender":"male",
"homeworld":"https://swapi.dev/api/planets/10/",
"films":[
"https://swapi.dev/api/films/2/",
"https://swapi.dev/api/films/3/",
"https://swapi.dev/api/films/5/"
],
"species":[
],
"vehicles":[
],
"starships":[
"https://swapi.dev/api/starships/21/"
],
"created":"2014-12-15T12:49:32.457000Z",
"edited":"2014-12-20T21:17:50.349000Z",
"url":"https://swapi.dev/api/people/22/"
}
]
}
Oczywiście odwołując się do podanych w JSON endpointów dostaniemy kolejne dane np o statku Slave 1 z url “https://swapi.dev/api/starships/21/”
{
"name":"Slave 1",
"model":"Firespray-31-class patrol and attack",
"manufacturer":"Kuat Systems Engineering",
"cost_in_credits":"unknown",
"length":"21.5",
"max_atmosphering_speed":"1000",
"crew":"1",
"passengers":"6",
"cargo_capacity":"70000",
"consumables":"1 month",
"hyperdrive_rating":"3.0",
"MGLT":"70",
"starship_class":"Patrol craft",
"pilots":[
"https://swapi.dev/api/people/22/"
],
"films":[
"https://swapi.dev/api/films/2/",
"https://swapi.dev/api/films/5/"
],
"created":"2014-12-15T13:00:56.332000Z",
"edited":"2014-12-20T21:23:49.897000Z",
"url":"https://swapi.dev/api/starships/21/"
}
Może coś o planecie Tatooine? Nie ma problemu: “https://swapi.dev/api/planets/1/”
{
"name":"Tatooine",
"rotation_period":"23",
"orbital_period":"304",
"diameter":"10465",
"climate":"arid",
"gravity":"1 standard",
"terrain":"desert",
"surface_water":"1",
"population":"200000",
"residents":[
"https://swapi.dev/api/people/1/",
"https://swapi.dev/api/people/2/",
"https://swapi.dev/api/people/4/",
"https://swapi.dev/api/people/6/",
"https://swapi.dev/api/people/7/",
"https://swapi.dev/api/people/8/",
"https://swapi.dev/api/people/9/",
"https://swapi.dev/api/people/11/",
"https://swapi.dev/api/people/43/",
"https://swapi.dev/api/people/62/"
],
"films":[
"https://swapi.dev/api/films/1/",
"https://swapi.dev/api/films/3/",
"https://swapi.dev/api/films/4/",
"https://swapi.dev/api/films/5/",
"https://swapi.dev/api/films/6/"
],
"created":"2014-12-09T13:50:49.641000Z",
"edited":"2014-12-20T20:58:18.411000Z",
"url":"https://swapi.dev/api/planets/1/"
}
Dokumentacja posiada wiele przykładów, warto ją sprawdzić 🙂
https://swapi.dev/documentation