KimiorV Posted June 26, 2023 Share Posted June 26, 2023 (edited) Introduction 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 <config> <public>false</public> <port>8080</port> </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. */ switch(path) { 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() }); } break; 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 August 30, 2023 by KimiorV 2 Quote Link to comment Share on other sites More sharing options...
KimiorV Posted July 31, 2023 Author Share Posted July 31, 2023 From now there is also module for client http request: https://gitlab.com/tomasz-k/httpclient_g2o (examples in readme) Quote Link to comment Share on other sites More sharing options...
KimiorV Posted August 30, 2023 Author Share Posted August 30, 2023 (edited) For some time, both the client and server modules have been published through the same repository at https://gitlab.com/tomasz-k/http. The complete documentation will be released around the end of the week... Edit: New docs - https://tomasz-k.gitlab.io/http/ Edited September 4, 2023 by KimiorV Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.