A http server to work with web applications written in Lua language check the site.
Installation
To install Pegasus.lua, run:
$ luarocks install pegasus
How does it work?
Follow an example:
local pegasus = require 'pegasus'
local server = pegasus:new({
port='9090',
location='example/root'
})
server:start(function (request, response)
print "It's running..."
end)
Features
- Compatible with Linux, Mac and Windows systems
- Easy API
- Support Lua >= 5.1
- Native support for HTTP Streaming, aka chunked responses. Check how it works.
- Native plugin to compress responses using the "gzip" method
API
Request
Properties
path
A string with the request pathheaders
A table with all the headers datamethod
The output is the request method as a string ('GET', 'POST', etc)querystring
It returns a dictionary with all the GET parameterspost
It returns a dictionary with all the POST parametersip
It returns the client's ipport
It returns the port where Pegasus is running
Response
Methods
addHeader(string:key, string:value)
Adds a new headeraddHeaders(table:headers)
It adds news headersstatusCode(number:statusCode, string:statusMessage)
It adds a Status CodecontentType(string:value)
Adds a value to Content-Type fieldwrite(string:body)
It creates the body with the value passed as parameterwriteFile(string:file)
It creates the body with the content of the file passed as parameter
local pegasus = require 'pegasus'
local server = pegasus:new({ port='9090' })
server:start(function (req, rep)
rep:addHeader('Date', 'Mon, 15 Jun 2015 14:24:53 GMT'):write('hello pegasus world!')
end)
Native Plugin
- pegasus.compress
local Pegasus = require 'pegasus'
local Compress = require 'pegasus.compress'
local server = Pegasus:new({
plugins = { Compress:new() }
})
server:start()
Contributing
Install Dependencies
$ make install_dependencies
Running tests
$ make test