NAME

SPRAGL::Cgi_reply - Simple HTTP replies.

VERSION

1.30

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.

FUNCTIONS AND VARIABLES

Loaded by default: fail, redirect, reply, reply_file, reply_html, reply_json, set_header, 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 the redirect method. If the name is anything else, a header with that name and value will be inserted in the reply. The header will be normalized, by capitalizing words and changing underscores to dashes. The header value will be inserted raw. Be sure to adhere to RFC 8187.

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.

DEPRECATED

DEPENDENCIES

File::Basename

File::Spec

JSON

KNOWN ISSUES

No known issues.

TODO

SEE ALSO

SPRAGL::Cgi_read

CGI

LICENSE & COPYRIGHT

(c) 2022-2023 Bjørn Hee

Licensed under the Apache License, version 2.0

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