Web-API [v4] - AdminPanel & RESTful web server [now with screenshots!]


Well, nope :stuck_out_tongue:

I can only get the events-all hook to work.

Here is my config : https://pastebin.com/Qmb7ka3v
event_join.php : https://pastebin.com/NMViJXDi
event_log.txt (tried with login, suicide, get wood, logout) : https://pastebin.com/rxHk3uzq
console output : https://pastebin.com/izppGWF4

No error during startup, still using a fresh install with latest vanilla sponge 5.2

What is wrong in my config ?

Edit : added console ouptut pastebin


Thank you for all the log files, I found the error, it has to do with the config files (once again, I honestly HATE how Sponge currently solved this...). I'll try and fix this as soon as I can.

@Keuterio for now I suggest using the all event hook, and then checking $_SERVER for the "X-WEBAPI-EVENT" header that will tell you which event it is


I do my best to provide enough information it's easier for you to fix the problem :slight_smile:

Nice suggestion, I now listen to $_SERVER['HTTP_X_WEBAPI_EVENT'] and it works like a charm :

However, I can wait for next update as I am not in a hurry.

Don't you have any support button ?

Edit : By chance, could you had hook "use" (button press) ? And if possible, "open" (open chest) ?. Only if they are not fired too often, I don't want to overload the requests.


Was gonna ask, is it possible for us to add sponge (or other plugin) events onto the hooks file in order to notify the server about these events being triggered and respond to it accordingly.
(I believe GriefPrevention is adding claimEnter and claimLeave events and want the server to be notified when they happen)


Very interesting idea. I could definitely add that. I'll have to look into how to turn the event data into nice json.


Even better if we can hook in whatever event we like. That could lead to a real interest for a server website.

I hope @Valandur will find an easy way to implement it :slight_smile:


Sorry for the late reply @Keuterio and @tridaak.

I've been working on a new version that supports custom events and serializers, and am happy to say that I'm almost done. Most of the stuff is in the git repository but I haven't released a new version yet because it needs more testing and documentation.

How this is going to work is that you can specify any event you want to subscribe to. In case you're not sure about the events you can check the /class endpoint which now supports looking up subclasses of a certain class. The Web-API will serialize all data which it knows how to into json. But if that's not good enough you can now write your own serializer which will get compiled and loaded when the server runs.

Let me make a short example:

You have to create a class that extends from the Jackson StdSerializer. The file has to have the same name as the class. E.g. the following file could be placed into the /webapi/serializers folder (not the config folder):

package serializers;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import me.ryanhamshire.griefprevention.api.event.ClaimEvent;

import java.io.IOException;

public class ClaimEventSerializer extends StdSerializer<ClaimEvent> {

    public ClaimEventSerializer() {

    public ClaimEventSerializer(Class<ClaimEvent> t) {

    public void serialize(ClaimEvent value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        gen.writeStringField("owner", value.getOwnerName());

Together with a custom event in config/webapi/hooks.conf along the lines of:

custom {

Would then cause the ClaimEvent from GriefPrevention to be serialized and sent to the hook.

I'm probably going to set up a repository or something to collect some common serializers.

Tell me what you guys think of that, and I'll probably be releasing a new version sometime this weekend.


:open_mouth: Amazing work, can't wait till it's done!


@Valandur coming with the new feature, only 3 days after initial suggestion :

Much incredible, very astonishing, wow.

Did you fix configuration issue as well ?


I have released version 3.1.0 with the following changes:

  • Add support for custom serializers
  • Rework class endpoint
  • Add ageable data
  • Add support for fetching custom fields and methods without an extra call
  • Add optional parameters to command hooks
  • Fix config files once again
  • Improve error responses
  • Rework hooks structure

Custom serializers now work and are documented.

You can also get arbitrary fields when getting the details of any player/entity/world/tile-entity by using the query parameters fields and methods (methods must have no arguments and must not return void).

A call would then look like this:


Wooooow, I'm on my way to play with postman :smiley:


I prefer making a new post than editing the previous one because I have some updates.

After trying to figure out how serializers work, I saw the "custom" line in hooks. As a test, I tried with org.spongepowered.api.event.block.ChangeBlockEvent and org.spongepowered.api.event.block.InteractBlockEvent

The hook is added and the request is sent to the webserver but I have an issue with datas.

All I get is the position of the player and no information about the targetted block :
https://pastebin.com/R87aMYcs + http://json.parser.online.fr/

My goal is still to hook "press button event" and "open chest event".

Of course, that's a super nice update :wink:

Edit : it didn't like org.spongepowered.api.event.entity.living.humanoid.HandInteractEvent https://pastebin.com/iXdzhfb3


What if you use the following serializer:

package serializers;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.spongepowered.api.event.block.InteractBlockEvent;
import valandur.webapi.json.serializers.WebAPISerializer;

import java.io.IOException;

public class InteractEventSerializer extends WebAPISerializer<InteractBlockEvent> {
    public void serialize(InteractBlockEvent value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        gen.writeObjectField("cause", value.getCause());
        gen.writeObjectField("block", value.getTargetBlock());

with the org.spongepowered.api.event.block.InteractBlockEvent?

There are still quite a few events that aren't very well supported. I'll try and add them when I can.


The weird part is that it doesn't load the serializer :

[10:11:16 INFO] [webapi]: Loading additional serializers...
[10:11:16 INFO] [webapi]: Found 0 serializer files in C:\Users\Administrateur.DESKTOP-AG15HPJ\Documents\Minecraft\test 1.10\webapi
[10:11:16 INFO] [webapi]: Starting Web Server...

I tried to name it InteractEventSerializer and InteractEventSerializer.class as well as putting it in server/webapi and server/webapi/serializers

Maybe it's the wrong name ?

Edit : I don't need to hook interactions with villagers, it was just to try an other event. Don't bother looking at it now unless someone else need it.

Edit 2 : I named it .java in server/webapi/serializers and webapi found it but doesn't like it :


Oh that is totally my bad, I forgot to mention that you have to name it .java.

Also it seems that you might need the jdk installed, not the jre... which might be rather cumbersum to do for most people. I'll see if I can fix/change that.

For now if you want to try it you'd have to install a JDK and use that to run the server. It shouldn't affect anything else and you dont have to remove the JRE.


So ClasseNameSerializer.java is the good name. Don't worry, it will be useful for the documentation later :slight_smile:
By the way, why don't you add hooks in redoc ? With examples and option, I could never think of "dataType" without your advice.

I have access to my dedicated server so it's not a problem for me and I think that advanced server owners who need to implement special hooks also own a ssh and sudo access. Maybe you can put a low priority on this issue. Can you install jre on your server tridaak ?

I installed JDK8 -not JRE8- on my computer, ran it again and here is what I got :

[NOTE] SpongePowered MIXIN Annotation Processor Version=0.6.8
[NOTE] ObfuscationServiceMCP supports type: "searge"
[NOTE] ObfuscationServiceMCP supports type: "notch"
[ERROR] Line 3:34 | package com.fasterxml.jackson.core does not exist
[ERROR] Line 4:38 | package com.fasterxml.jackson.databind does not exist
[ERROR] Line 5:41 | package org.spongepowered.api.event.block does not exist
[ERROR] Line 6:40 | package valandur.webapi.json.serializers does not exist
[ERROR] Line 10:46 | cannot find symbol
symbol: class WebAPISerializerInteractBlockEvent
[ERROR] Line 12:27 | cannot find symbol
symbol: class InteractBlockEvent
location: class serializers.InteractEventSerializer
[ERROR] Line 12:53 | cannot find symbol
symbol: class JsonGenerator
location: class serializers.InteractEventSerializer
[ERROR] Line 12:72 | cannot find symbol
symbol: class SerializerProvider
location: class serializers.InteractEventSerializer

No idea what does it mean..

Also it seems like I am speaking too much :joy:


Havent gotten to really test it out, installed new version on my test server to see if it'll run and it's working. Had to change the port because commands for main server were going to test server's web-api, aside from that, the configuration is the same as the default.
So everything in the hooks.conf is either null or disabled.

Got the following today: https://pastebin.com/uz4Jd0nE

I'll have more time to test stuff out, do have a private server where I can install JDK (seems that's what's needed), later when I have more free time. Otherwise @Keuterio you could try installing JDK and see if it works for you.


Hell, I meant "I installed JKD8", not JRE8 :x


Do you mind sharing the serializer you used? I believe this might have to do with the fact that I shadow the libraries, so the references are then incorrect.

Sorry for staying so quiet, I've been quite busy lately.


A new version has been released for Web-API, it is available for download here.

  • Support SpongeAPI 7.0..0
  • Improve serializer feedback & support shadowed packages
  • Fix error for query strings without an equals sign [r15ch13]