Jump to content

[Server] httpserver_g2o


Recommended Posts


The httpServer module integrates a third-party HTTP server library which enables communication with your server using methods such as POST, GET, PUT, and DELETE, eliminating the need for constant checking and updating of the state in your MySQL database.

Project link:
- Repository
- Download (always check for newest)

How to config


Setting the value to false is recommended. With this configuration, your API will only work on the local interface. If you want to access it outside of your VPS, set the value to true.

How to use - send request

JavaScript - https://axios-http.com/docs/api_intro
PHP Symfony - https://symfony.com/doc/current/http_client.html

How to use - receive and response

addEventHandler("http:onRequest", function (path, request, response) 
    print(request.addres); // sender address -- string
    print(request.method); // method POST/GET/PUT/DELETE -- string
    print(request.content_type); // content type -- string
    print(request.body); // request body -- string

        If body is in JSON format you can use http.unpackJSON(request.body) to transform it into table.

        case "/status":
            response.content_type = "application/json"; // same as in request -- string
            response.status = 200;

                If you want to send JSON in response you can use http.packJSON(table) to transform squirrel table into JSON object.
            response.body = httpServer.packJSON({ count = getPlayersCount(), max_slots = getMaxSlots() });
        default: response.status = 404; // http response status -- integer 


I recommend using this module in a private environment. If you need to provide access outside, you can use a proxy created with frameworks like Symfony(PHP) or others...

Big thanks to Patrix for help with concept and JSON functions!
Edited by KimiorV
  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...