reserved 1.0.1

A minimal library to run your D application on your webserver using scgi


To use this package, put the following dependency into your project's dependencies section:

dub.json
dub.sdl

Reserved

A scgi client for D programming language. Doc: dpldocs

The simple way

#!/usr/bin/env dub
/+ dub.sdl:
        name "awesome_d_webservice"
        dependency "reserved" version="1.0.0"
+/

import reserved;
import std.stdio;

@ReservedResponse
private void response(Request req, Output output)
{
   output ~= "Hello ";
   
   if ("name" in req.get) 
      output ~= req.get["name"];
   else 
      output ~= "World";
}

mixin Reserved!"awesome_d_webservice";

Starting this example will create a socket named `/tmp/run/awesome_d_webservice/listener.0.sock`. If another process is still running on the same socket it will be (gracefully) killed.

Configure the server

To make nginx (for example) working with reserved just add these lines on its config file (on ubuntu: `/etc/nginx/sites-available/default`) and restart nginx:

location / {
                include   scgi_params;
                scgi_pass unix:/tmp/run/awesome_d_webservice/listener.0.sock;
        }

Pay attention to sock file permission. Both your application and nginx must have permission to read/write that file. The easy way is to run both with the same user.

Once the server is running, just browse to http://localhost/?name=D

Init function

If you need to call a one-time-init function, you can annotate it with `@ReservedInit`. Its signature must be one of these:

bool init()

// will be called using main() args
bool init(string[] args)

It musts return true on success.

Multiple responders

If you want to run multiple parallel responders, just use `-i options on command line. For example ./your_app -i 3 will create a socket named /tmp/run/awesome_d_webservice/listener.3.sock` and/or will kill any process running on it.

Authors:
  • Andrea Fontana
Dependencies:
none
Versions:
1.0.1 2018-Jul-05
1.0.0 2018-May-16
~master 2018-Jul-05
Show all 3 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 3 downloads total

Score:
0.9
Short URL:
reserved.dub.pm