dcgi 0.1.0

Simple and light CGI library for D


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

dcgi

Simple and light CGI library for D

Basic example

import dcgi;

mixin DCGI; // Needed for boilerplate code

void cgi(Request req, Output output) 
{
  output("Hello, world");
}

Full example

/+ dub.sdl:
name "Hello_dcgi"
description "A minimal dcgi application."
dependency "dcgi" version="~>0.1.0"
+/

import dcgi;

mixin DCGI!my_cgi_function; // Custom function

@DisplayExceptions // Show exceptions directly on output
@MaxRequestBodyLength(1024) // Limit request body to 1kb
void my_cgi_function(Request request, Output output) 
{
  output.status = 201; // Default is 200
  output.addHeader("content-type", "text/plain"); // Default is text/html
  output("Hello, world");
  
  if ("REQUEST_URI" in request.header)
    output("Uri:", request.header["REQUEST_URI"]);
}

Notes

  • stdout is redirected to stderr.
  • a simple cgiLog function is included for debug purpouses.
  • tested on linux only.
Authors:
  • Andrea Fontana
Dependencies:
none
Versions:
0.1.0 2020-Feb-14
~master 2020-Feb-14
Show all 2 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 32 downloads total

Score:
1.1
Short URL:
dcgi.dub.pm