Jump to content

L2jRest - An L2j Rest API


Recommended Posts

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

Edited by Elfocrash
  • Like 4
  • I love it 1
Link to comment
Share on other sites


8 minutos atrás, Elfocrash disse:

I don't know whats nWatch. Can you give me an example?

https://www.l2sublimity.com/forum/view/7952-nostalgia-first-nwatch-concept/

You are able to see status/equipment/etc of any player. Just putting the nickname.

Sry for not having an online example.

Edited by PeNaChO

   

Link to comment
Share on other sites

Thanks guys.

Changed the way handlers are registered. Now they will be scanned automatically during server startup and they will be registered based on their annotation. This means that all you have to do to add a new endpoint is to create a request handler and add the Get, Post etc annotation.

  • I love it 1
Link to comment
Share on other sites

  • L2JBr ADM

Nice work!

 

I never read nothing about this language, I need to look at it for sure!

If it was to PHP I have a perfect library to implement cross  revision support https://github.com/L2jBrasil/L2JPHP (not mature yet but could be with some help)

?

 

EJoOSOj.gif

Sua pergunta foi respondida? Certifique-se de marcar a resposta como a solução aceita.
Se existe mais de uma resposta, utilize o "vote up" para destacá-la.
Se você achar uma resposta útil, diga obrigado clicando no botão "Gostei".

Link to comment
Share on other sites

16 hours ago, Grundor said:

I never read nothing about this language, I need to look at it for sure!

If it was to PHP I have a perfect library to implement cross  revision support https://github.com/L2jBrasil/L2JPHP (not mature yet but could be with some help)

?

 

It's very good. It's like a way better java (combines C#, Scala and Java) and it has proper async support with coroutines. This API is insanely fast.

I've seen the l2jphp. It is quite different since L2jRest runs from within the server to provide real time metrics. L2jphp goes straight to the database right?

Update

  • Added api key based authentication as requested. Requests will only be served when the x-api-key header is set with the configured value.
  • Like 2
Link to comment
Share on other sites

  • L2JBr ADM
18 minutos atrás, Elfocrash disse:

It's very good. It's like a way better java (combines C#, Scala and Java) and it has proper async support with coroutines. This API is insanely fast.

I've seen the l2jphp. It is quite different since L2jRest runs from within the server to provide real time metrics. L2jphp goes straight to the database right?

Update

  • Added api key based authentication as requested. Requests will only be served when the x-api-key header is set with the configured value.

Yes, its most to the php+mysql envs such remote websites and something like that.

 

For sure an internal API running among the server will be insanely fast, a build-in server with an HTTP API would be very nice for development. 

EJoOSOj.gif

Sua pergunta foi respondida? Certifique-se de marcar a resposta como a solução aceita.
Se existe mais de uma resposta, utilize o "vote up" para destacá-la.
Se você achar uma resposta útil, diga obrigado clicando no botão "Gostei".

Link to comment
Share on other sites

  • 2 months later...



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.