Home

Awesome

lua-httpconsts

HTTP method names and status code constants module.

Installation

luarocks install --from=http://mah0x211.github.io/rocks/ httpconsts

or

git clone https://github.com/mah0x211/lua-httpconsts.git
cd lua-httpconsts
luarocks make rockspecs/httpconsts-<version>.rockspec

HTTP Method Module

Supported Method Names

Usage

local Method = require('httpconsts.method');

print( Method.consts.GET ); -- 'GET'
print( Method.consts.get ); -- 'GET'

-- export uppercase method name to global table
Method.export( _G );
print( GET ); -- 'GET'
print( get ); -- nil

HTTP Status Module

Supported HTTP Status Code

Usage

local Status = require('httpconsts.status');

print( Status.consts.OK ); -- 200
print( Status.consts[200] ); -- 'OK'

-- export status name to global table
Status.export( _G );
print( OK ); -- 200

toStatusLineName( statusCode )

returns a status line string correspond to the status code.

Parameters

Returns

  1. string or nil

**Usage **

local Status = require('httpconsts.status');
print( Status.toStatusLineName( 414 ) ); -- 'Request-URI Too Long'

Utility Function

httpconsts.export function can export both of method-names and status-code.

Usage

local HttpConsts = require('httpconsts');
HttpConsts.export( _G );

print( GET ); -- 'GET'
print( OK ); -- 200