So I was bored again...
L2jRest is a RESTful API for L2j
It is created for latest aCis but you should be able to adapt it is you wanna use it for other projects.
L2jRest is an open source project licensed under MIT. You can find the source here: https://github.com/Elfocrash/L2jRest
Why use it?
You can use the data of your server in your website
You can create an account control panel with it
You can expose data to your community to allow them to make third party apps
Technical stuff
It is written in Kotlin.
It is using the Ktor framework. Ktor is using coroutines to achieve asynchronous request handling. It is very efficient and very fast.
It is using Netty as the underlying server.
It is written in a CQRS manner with query handlers for get endpoints and command handlers for post, put, patch, delete etc.
It is using Koin as the IoC framework.
How to setup
Download and install Intellij IDEA
Git clone the project and open it with Intellij
Run the build Gradle task. It is configured to create a fat jar with all the dependencies included
Paste the jar in your project, add it in your classpath and add the following line at the bottom of your Gameserver.java: L2jRestApi.INSTANCE.start();
Running the gameserver will also run the api. It is running under port 6969
How to extend it
All you need to do if you wanna add more endpoints is to add a new handler and then add the Get, Post etc annotation depending on what endpoint you want this to be.
Current endpoints:
http://localhost:6969/api/players
http://localhost:6969/api/players/{id}
A couple of endpoint examples
Endpoints: http://localhost:6969/api/players
Response:
{
players: [
{
"id": 268480927,
"name": "Test",
"level": 1,
"isOnline": false,
"pvpKills": 0,
"pkKills": 0,
"isNobless": false
},
{
"id": 268480924,
"name": "Test2",
"level": 1,
"isOnline": true,
"pvpKills": 0,
"pkKills": 0,
"isNobless": false
}
]
}
Endpoint: http://localhost:6969/api/players/268480927
Response:
{
"id": 268480927,
"name": "Test",
"level": 1,
"isOnline": false,
"pvpKills": 0,
"pkKills": 0,
"isNobless": false
}
Currently it just supports two endpoints and no authentication. I am planning to add more endpoints and ApiKey based auth tomorrow.
If you can't be arsed to build the project yourself but you wanna take a look anyway you can download the jar here