Skip to content
THEHHOY edited this page Jul 2, 2025 · 3 revisions

About

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()

Contents

api.new(port)

With this you make a new server object. With a server object you can use server methods to make it functional

server:listen(route, method, func)

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()

server:run()

Runs your server

Clone this wiki locally