cgi
Common Gateway Interface (CGI) in Gleam.
CGI is not commonly used these days, but there scenarios where it is still a good choice. As CGI programs only run when there is a request to handle they do not use any system resources when there is no traffic. This makes them very efficient for low traffic websites.
gleam add cgiimport cgi
import gleam/string
pub fn main() {
use request <- cgi.handle_request
let headers = [#("content-type", "text/plain")]
let body = "Hello! You send me this request:\n\n" <> string.inspect(request)
Response(201, headers, body)
}You may wish to compile your Gleam program to an escript to be run by your CGI server.
Further documentation can be found at https://hexdocs.pm/cgi.
Thank you to Steven vanZyl for plug_cgi, which was used as a reference. Why is there so little information on the CGI protcol online these days?