NAME

SPRAGL::Cgi_reply - Simple HTTP replies.

VERSION

1.10

SYNOPSIS

use SPRAGL::Cgi_reply;

my %df = map {(/^(\S+).+\s(\d+)\%/)} grep {/\d\%/} qx[ df ];
reply_json \%df;

DESCRIPTION

Simple module for sending simple HTTP replies. Geared towards CGI scripts.

CGI is simple and quick to code for, even though it is not so performant or fashionable. It nevertheless is handy when making quick and dirty web services that are not going to see a lot of load. HTTP Routing is handled by the file system. Adding or removing functionality is easy and orthogonal, like playing with Lego bricks.

The reply methods in SPRAGL::Cgi_reply will exit when they have been called. The exit is based on "die". So it is catchable, END blocks will execute, et cetera.

FUNCTIONS AND VARIABLES

Loaded by default: fail, redirect, reply, reply_html, reply_json, csystem, cexec

Loaded on demand: %status_code

OPTIONAL NAMED PARAMETERS

Optional named parameters can be given in the reply calls. If the name is "redirect" the reply will be like calling redirect. If the name is anything else, a header with that name and value will be inserted in the reply.

Examples:

reply $x.' seconds to go!' , refresh => 5; # Inserts a "Refresh: 5" header.

fail 503 , 'We are down at the moment, please try again later' , 'Retry-After' => $t;

fail 308 , redirect => 'https://perlmaven.com/'; # Redirecting with another code than 302.

DEPENDENCIES

File::Spec

JSON

KNOWN ISSUES

No known issues.

TODO

SEE ALSO

SPRAGL::Cgi_read

CGI

LICENSE & COPYRIGHT

(c) 2022-2023 Bjrn Hee

Licensed under the Apache License, version 2.0

https://www.apache.org/licenses/LICENSE-2.0.txt