Skip to content

jkingster/J-SWAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

J-SWAPI

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.

Table of contents

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

Please note before using:

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.

Getting Started

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.

Getting By ID

RequestAction#getById(Int) -> T

class GettingStarted {
    public static void main(String[] args) {
        var person = SWAPI.person().getById(2);
    }
}

Getting All

RequestAction#getAll() -> List<T>

class GettingStarted {
    public static void main(String[] args) {
        List<Films> films = SWAPI.films().getAll();
    }
}

Getting By Search

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.

Getting By Filter

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
        );
    }
}

Getting First By Search

RequestAction#getFirstBySearch(String) -> Optional<T>

class GettingStarted {
    public static void main(String[] args) {
        SWAPI.films().getFirstBySearch("hope").ifPresent(System.out::println);
    }
}

All methods are static and can be called from our core SWAPI class.

SWAPI.(resource).getAll()

SWAPI.(resource).getById(Int)

SWAPI.(resource).getBySearch(String)

SWAPI.(resource).getFirstBySearch(String)

SWAPI.(resource).getByFilter(Predicate<T>)

Dependencies

  • Jackson - Reading & Parsing JSON.

Known Issues

Elements skip certain indexes, read here

Todolist

Nothing currently.

About

A helper library in Java for SWAPI.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages