-
Notifications
You must be signed in to change notification settings - Fork 1
Server
THEHHOY edited this page Jul 2, 2025
·
3 revisions
Makes your webserver work
Example webserver:
local mchttpserver = require("mchttp-server")
local app = mchttpserver.new(80)
app:listen("/echo","GET",function(pack)
return {body=pack.body,contentType="text/plain"}
end)
app:listen("/post","POST",function(pack)
print("MSG:",pack.body)
end)
app:run()With this you make a new server object. With a server object you can use server methods to make it functional
You use this to listen to a route and if its a specified method and if you request the server from client with the method and route it runs the function with parameter: packet
Example of method get:
local api = require("mchttp-server")
local server = api.new(80)
server:listen("/echo","GET",function(packet)
return {body=packet.body,contentType="text/plain"}
end)
server:run()Example of method POST:
local api = require("mchttp-server")
local server = api.new(80)
app:listen("/post","POST",function(pack)
print("MSG:",pack.body)
end)
server:run()Runs your server