Getting started

This will teach you how to use the API, including all features.

During the entire wiki page you will encounter that I often use final on variables or method parameters. This is just my style of coding and you can leave it away if you do not have the same code style.

Go ahead and create a new class within your project folder. This class needs to have a main method to run the example code, you can then adjust it to your own needs. Within your main method you will need to load up the API. You can then create a new instance of the API, which is used for the required methods.

I recommend putting this API into a class variable, and pass it on into classes where you need them.

import me.kazury.enkanetworkapi.enka.EnkaNetworkAPI;

public class Main {
    public static void main(String[] args) {
        final EnkaNetworkAPI api = new EnkaNetworkAPI().build();
    }
}

Blocking specific caches

For some people, if the library takes longer to load (4.5 introduced 5 new caches) you can disable specific caches. This is done on the EnkaNetworkAPI instance. It is recommended that you read the documentation on EnkaCacheobjects before blocking them.

DO NOT COPY THE SNIPPET INTO YOUR CODE. THIS IS FOR DEMONSTRATION.

final EnkaNetworkAPI api = new EnkaNetworkAPI();

api.setBlockedCaches(EnkaCache.GENSHIN_MATERIALS);
api.build();

setBlockedCaches reloads all caches. It is recommend that you call this once upon startup and not after specific actions


Global Localization

You can set a localization which is used for when you need to retrieve something from the TextMap. Make sure to call build after you are done with your changes.

api.setDefaultLocalization(GlobalLocalization.GERMAN);

User Agent

You can set a user agent which is sent to enka.network when making HTTP requests.

If you ever come across rate limits, then the User Agent is very important so that Algoinde can help increase those limits, however there is a limited queue of requests per minute, so this should not happen. Make sure to call build after you are done with your changes.

api.setUserAgent(...);

Make sure to use something that is good to read, could be your name, or something else.

Do not disguise as a browser.


UI Path

You can also set a custom UI path, which is used when you are requesting png's by an identifier. Make sure to call build after you are done with your changes.

api.setDefaultUIPath(...);

Honkai: Star Rail Support

Yes, as of version 4.0 I have added Honkai: Star Rail Support. If you want to use Honkai: Star Rail in your project, you need to enable it on the api loader. Make sure to call build after you are done with your changes.

I will not make extra documentation on Honkai: Star Rail because it is the same concept as Genshin Impact, if there is any additions that need documentation, I will add it.

api.enableHonkai(true);

If you do not need Honkai: Star Rail in your project then you also do not need to enable it. It may lead to higher loading times for localizations on start.


Zenless Zone Zero Support

Yes, as of version 5.4 I have added Zenless Zone Zero Support. If you want to use Zenless Zone Zero in your project, you need to enable it on the api loader. Make sure to call build after you are done with your changes.

I will not make extra documentation on Zenless Zone Zero because it is the same concept as Genshin Impact and Honkai: Star Rail, if there is any additions that need documentation, I will add it.

api.enableZenless(true);

If you do not need Zenless Zone Zero in your project then you also do not need to enable it. It may lead to higher loading times for localizations on start.


EnkaNetworkBuilder

Some people prefer a factory pattern over a class with multiple voids.

So, you can use EnkaNetworkBuilder for this.

import me.kazury.enkanetworkapi.enka.EnkaNetworkAPI;
import me.kazury.enkanetworkapi.enka.EnkaNetworkBuilder;
import me.kazury.enkanetworkapi.util.GlobalLocalization;

public class Main {
    public static void main(String[] args) {
        final EnkaNetworkAPI api = new EnkaNetworkBuilder()
                .setUserAgent(...)
                .setDefaultLocalization(...)
                .build();
    }
}

Retrieving image png's

There are some methods in the API which return an icon identifier.

You will need the identifier if you want to get a png from the identifier.

final String identifier = "UI_AvatarIcon_Furina";

api.getGenshinIcon(identifier); // returns the png from the ui path. 
Furina, the God of Justice, she's beautiful

Rate Limits

When retrieving data (calling any fetch method) an HTTP request will be made to https://enka.network/api/uid/x/ and it is obvious that you cannot do infinite requests in a period.

Though, it is not strictly "x requests per s/min", but it's more of a bucket that fills up, if it goes overboard then you will be pushed towards the rate limit by delaying the requests. If you still manage to go over that bucket, you will be getting a RateLimitedException.


Last updated

Was this helpful?