Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/motemen/http-response-maker
easy HTTP response object maker functions
https://github.com/motemen/http-response-maker
Last synced: about 1 month ago
JSON representation
easy HTTP response object maker functions
- Host: GitHub
- URL: https://github.com/motemen/http-response-maker
- Owner: motemen
- Created: 2012-03-31T07:01:14.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2013-01-09T09:42:56.000Z (almost 12 years ago)
- Last Synced: 2024-10-15T15:30:34.574Z (3 months ago)
- Language: Perl
- Homepage:
- Size: 117 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changes
Awesome Lists containing this project
README
# NAME
HTTP::Response::Maker - easy HTTP response object maker functions
# SYNOPSIS
use HTTP::Response::Maker 'HTTPResponse', (
default_headers => [
'Content-Type' => 'text/html; charset=utf-8'
],
prefix => 'RESPOND_',
);# now you can use functions like RESPOND_OK() or RESPOND_NOT_FOUND()
or
use HTTP::Response::Maker::Exception prefix => 'throw_';
throw_FOUND([Location => '/']);
# DESCRIPTION
HTTP::Response::Maker provides HTTP response object maker functions.
They are named as `OK()` or `NOT_FOUND()`, corresponding to
the [HTTP::Status](http://search.cpan.org/perldoc?HTTP::Status) constant names.# USAGE
## use HTTP::Response::Maker _$impl_, _%args_;
Exports HTTP response maker functions to current package.
_$impl_ specifies what functions make. See IMPLEMENTATION.
_%args_ has these keys:
- prefix => ''
Prefix for exported functions names.
- default\_headers => \\@HTTP::Response::Maker::DefaultHeaders
Default HTTP headers in arrayref.
# IMPLEMENTATION
`import()`'s first argument specifies what type of objects functions generate.
Currently it is one of:- [HTTPResponse](http://search.cpan.org/perldoc?HTTP::Response::Maker::HTTPResponse)
Generates an [HTTP::Response](http://search.cpan.org/perldoc?HTTP::Response) object.
- [PSGI](http://search.cpan.org/perldoc?HTTP::Response::Maker::PSGI)
Generates an arrayref of [PSGI response](http://search.cpan.org/perldoc?PSGI#The\_Response) format.
- [Plack](http://search.cpan.org/perldoc?HTTP::Response::Maker::Plack)
Generates a [Plack::Response](http://search.cpan.org/perldoc?Plack::Response) object.
You can specify subclass of [Plack::Response](http://search.cpan.org/perldoc?Plack::Response) to generate:
use HTTP::Response::Maker 'Plack', class => 'Your::Plack::Response';
- [Exception](http://search.cpan.org/perldoc?HTTP::Response::Maker::Exception)
Throws an [HTTP::Exception](http://search.cpan.org/perldoc?HTTP::Exception).
# FUNCTION ARGS
Exported functions accept arguments in some ways:
my $res = OK;
my $res = OK $content;
my $res = OK \@headers;
my $res = OK \@headers, $content;# AUTHOR
motemen
# SEE ALSO
[HTTP::Status](http://search.cpan.org/perldoc?HTTP::Status), [PSGI](http://search.cpan.org/perldoc?PSGI), [HTTP::Response](http://search.cpan.org/perldoc?HTTP::Response), [HTTP::Exception](http://search.cpan.org/perldoc?HTTP::Exception)
# LICENSE
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.