J(ava)-SWAPI is a helper library for SWAPI, which is short for Star Wars API. It allows you to retrieve data relating to the following: People, Films, Starships, Vehicles, Species, and Planets.
Getting Started
Getting Resource By Id
Getting All of Resource type
Getting Resource by Search
Getting Resource(s) By Filter
Getting First Resource By Search
Dependencies
Known Issues
This API does not handle rate limiting, and according to the SWAPI website it allows 10,000 API requests per day. You can find that information documented here.
It should also be noted that no authentication is required per the website as well.
From here, we can retrieve the following resources that were mentioned above:
- People
- Films
- Starships
- Vehicles
- Species
- Planets
All resources provide the same routes, allowing you to retrieve via the following ways: SEARCH, ID, ALL, PAGE.
All resources extend RequestAction<T extends BaseResource>.
T is defined as our resource. So via our core SWAPI class, we have static action methods that return the desired resource we want.
RequestAction#getById(Int)
-> T
class GettingStarted {
public static void main(String[] args) {
var person = SWAPI.person().getById(2);
}
}
RequestAction#getAll()
-> List<T>
class GettingStarted {
public static void main(String[] args) {
List<Films> films = SWAPI.films().getAll();
}
}
ReuestAction#getBySearch(String)
-> List<T>
class GettingStarted {
public static void main(String[] args) {
List<Person> people = SWAPI.people().getBySearch("anakin skywalker");
}
}
Spaces are allowed via the search querying method, they are replaced for the URL automatically so using them is alright.
RequestAction#getByFilter(Predicate<T>
-> List<T>
class GettingStarted {
public static void main(String[] args) {
List<Starships> starshipsList = SWAPI.starships().getByFilter(
starship -> Double.parseDouble(starship.getHyperdriveRating()) >= 2.0
);
}
}
RequestAction#getFirstBySearch(String)
-> Optional<T>
class GettingStarted {
public static void main(String[] args) {
SWAPI.films().getFirstBySearch("hope").ifPresent(System.out::println);
}
}
SWAPI.(resource).getAll()
SWAPI.(resource).getById(Int)
SWAPI.(resource).getBySearch(String)
SWAPI.(resource).getFirstBySearch(String)
SWAPI.(resource).getByFilter(Predicate<T>)
- Jackson - Reading & Parsing JSON.
Elements skip certain indexes, read here
Nothing currently.