Kotlin client for https://pokeapi.co powered by coroutines.
- Full https://pokeapi.co REST API coverage (WIP)
- Caching out of the box
- Powered by coroutines
- No exceptions, everything wrapped into Result out of the box
- Both 1-1 with original API layer and enhanced 'fluid' version
- No transitive dependencies
- Ability to customize underlying HTTP engine (WIP)
- Ability to use custom PokeApi deployment
To get a Git project into your build:
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
maven { setUrl("https://jitpack.io") }
}
}
Step 2. Add the dependency
dependencies {
implementation("com.github.lexa-diky:pokeapi-kotlin:-SNAPSHOT")
}
Step 3. Use PokeApiClient
to access powerful API
val client = PokeApiClient { }
val bulbasaur = client.pokemon.get("bulbasaur")
// or blocking call
val pikachu = client.pokemon.blocking.get("pikachu")
To access particular resource this library provides so called GenericAccessor
objects. These accessors are defined in PokeApiClient
class (for
example client.pokemon
).
There are 2 kinds of methods:
all
- returns full list of resources available in accessorrange
- returns list of resources available in accessor in passedIntRange
Both methods return ResourceList
object containing results
list of ResourcePointer
to resource details and
next
, previous
and count
for paging.
get
- polymorphic method accepting either id: Int
, name: String
, pointer: ResourcePointer
, pointer: HasResourcePointer
to an resource.
Will return details of resource with passed identifier
There are 2 ways to implement paging resource access via this library.
- You can use
range
method on anyGenericAccessor
acceptingIntRange
of object ids. - Or you can use specialized paging api via
pages
method.
First approach is a bit more manual, you have to manage page size and id ranges manually.
Second approach is simpler. pages
accepts size of requested page and returns Paging
object with
two methods: first
- returns first page and get
- returns page by pointer from previous request. For example:
val client = PokeApiClient { }
val pages = client.pokemon.pages(size = 10)
val firstPage = pages.first().getOrThrow()
val secondPage = pages.get(firstPage.next!!).getOrThrow()
val firstPageAgain = pages.get(secondPage.previous!!)
Blocking API methods could be accessed via 'blocking' property on all accessors.
Blocking methods are 1-1 copy of suspended
ones, all async documentation applicable.
val client = PokeApiClient { }
val pikachu = client.pokemon.blocking.get("pikachu")
✅ Basic API access via get
and all
✅ Endpoint customization
✅ Java friendly blocking calls
✅ Type safe resource access via references in other resources
✅ Fluid API
✅ Documentation
🚧 All endpoints accessible
🚧 Optional integration with Kotlin Arrow library
🚧 Http client customization
🚧 Maven Central Artifact