🍮 PudimServer Docs

Module: PudimServer.http

HTTP request parsing and response generation.

http:ParseRequest(raw)

Transforms the raw HTTP string into a table with method, path, version, headers, body, query, and params.

Inputs: raw (string containing the full HTTP request).

Output: parsed Request table.

local http = require("PudimServer.http")
local req = http:ParseRequest(rawRequest)

http:response(status, body, headers?)

Builds the final HTTP response; when body is a table, it is automatically converted to JSON.

Inputs: status (number), body (string|table), headers? (optional table).

Output: HTTP string ready to send through the socket.

return http:response(200, { ok = true })

Supported Status Codes

The response method automatically maps these status codes to their reason phrase. Any unlisted code will produce an empty reason.

CodeReason Phrase
100Continue
101Switching Protocols
102Processing
200OK
201Created
202Accepted
204No Content
301Moved Permanently
302Found
304Not Modified
400Bad Request
401Unauthorized
403Forbidden
404Not Found
405Method Not Allowed
409Conflict
415Unsupported Media Type
422Unprocessable Entity
429Too Many Requests
500Internal Server Error
501Not Implemented
502Bad Gateway
503Service Unavailable
504Gateway Timeout