Copper OS

A operating system for computercraft and what goes with it.

View on GitHub

Cttp (Copper Text Transfer Protocol)

Cttp is a extension of CNet

Server Hosting

Cttp = require "Cttp"

-- Requests can be handled by defining Get, Post and Delete mappings
-- The request Cttp.GetRequest("/path", "Request message") will be handled by this function
Cttp.GetMapping("/path", function (body)
    print("Received request: " .. body)
    return 200, "Response message" -- Status code and response message
    -- Messages can be any lua data type that can be serialized
end)

-- Before hosting is possible, Cttp must be set up
Cttp.setup(function ()
    Cttp.host("server-name")
end)

Client Handling

Cttp = require "Cttp"

-- Before connecting or sending requests is possible, Cttp must be set up
Cttp.setup(function ()
    local socket = Cttp.connect("server-name")
    local response = Cttp.sendRequest(socket, Cttp.GetRequest("/path", "Request message"))
end)