All Projects → upvalue → luvit-heart

upvalue / luvit-heart

Licence: other
A micro web framework for Luvit

Programming Languages

lua
6591 projects

Projects that are alternatives of or similar to luvit-heart

bay
The framework
Stars: ✭ 20 (+33.33%)
Mutual labels:  web-framework
endpoints
Lightweight REST api backend framework that automatically maps urls to python modules and classes
Stars: ✭ 30 (+100%)
Mutual labels:  web-framework
quinn
A set of convenient helpers to use promises to handle http requests
Stars: ✭ 40 (+166.67%)
Mutual labels:  web-framework
stirfry
StirFry is a self contained and lightweight web framework for nodejs
Stars: ✭ 24 (+60%)
Mutual labels:  web-framework
recurse
Qt based micro web framework with middleware design
Stars: ✭ 19 (+26.67%)
Mutual labels:  web-framework
jimhttp
A library collection and web microframework
Stars: ✭ 25 (+66.67%)
Mutual labels:  web-framework
Fuga-Framework
Web Framework for Java
Stars: ✭ 15 (+0%)
Mutual labels:  web-framework
nova
Web framework for Erlang.
Stars: ✭ 175 (+1066.67%)
Mutual labels:  web-framework
ncms
Java CMS engine. Host and develop multiple websites inside a single instance through the GUI and benefit from features like A/B testing, affiliate tracking tools, and a high performance template engine with CSS stylesheets processing & scripts minification.
Stars: ✭ 32 (+113.33%)
Mutual labels:  web-framework
skinny-micro
🎤 Micro Web framework to build Servlet applications in Scala, the core part of Skinny Framework 2
Stars: ✭ 57 (+280%)
Mutual labels:  web-framework
Polyel-Framework
⚡️ Voltis Core: A PHP framework based on Swoole from the ground up
Stars: ✭ 22 (+46.67%)
Mutual labels:  web-framework
ult
The Ultimate Dev Stack
Stars: ✭ 54 (+260%)
Mutual labels:  web-framework
framework
The Peak Framework
Stars: ✭ 20 (+33.33%)
Mutual labels:  web-framework
mif
MIF is a C++11 web-application framework designed for the backend micro-service development
Stars: ✭ 42 (+180%)
Mutual labels:  web-framework
framework
Cygnite PHP Framework- A Modern Toolkit For Web Developers
Stars: ✭ 43 (+186.67%)
Mutual labels:  web-framework
aqua
A minimal and fast 🏃 web framework for Deno
Stars: ✭ 219 (+1360%)
Mutual labels:  web-framework
alef-component
Alef Component for Modern Web Apps.
Stars: ✭ 46 (+206.67%)
Mutual labels:  web-framework
portals-pluto
Mirror of Apache Pluto
Stars: ✭ 24 (+60%)
Mutual labels:  web-framework
multi-projects-architecture-with-Ktor
A Ktor real world example built on multi-projects architecture
Stars: ✭ 29 (+93.33%)
Mutual labels:  web-framework
jflask
Flask-inspired web micro-framework for Java (deprecated)
Stars: ✭ 18 (+20%)
Mutual labels:  web-framework

Heart is a micro web framework for luvit. It basically just dispatches URLs and provides a little sugar for dealing with HTTP requests and responses. Templates, sessions, and so forth are entirely up to you.

Released under the Apache License 2.0

Using

In your project directory:

mkdir -p modules/

git clone git://github.com/ioddly/luvit-heart.git modules/heart

Then create, say, main.lua

local app = require('heart').app()

app:get('/', function()
  return 'Hello, world!'
)

require('http').createServer(app):listen(8080)

Heart is definitely a little more verbose and explicit than Ruby micro frameworks. I like it that way. I've also tried not to add too much sugar, in case luvit ever gets a consensus middleware system like Rack. See sample.lua for a more complex example.

Documentation

Writing handlers

Handlers take the same arguments as the http.createServer callback does: req and res. See the luvit documentation for details on those objects (or the node.js documentation which is mostly the same).

req has an additional field added: heart, which contains any parameters given in the URL. For instance, if your route is /hello/:name, you can access name in your handler through req.heart.params.name

Once your handler is finished doing whatever it needs to do, you should return your response values. The simplest way to do this is to return a string, which will cause the server to respond with that string along with 200 OK and some relevant headers.

However, if you need to do more with http response codes, you can redirect stuff

return 301, '/new_url'

Return response codes

return 500, 'Server Error'

Or even return a code, body, and headers

return 500, 'Server Error', { ['Imaginary-Header'] = "It's late and I can't think up a header example" }

Finally, if you need to do something wacky with the response object (such as fire off a callback that will stream a file asynchronously), return 0 and heart will not send a response.

URL Routing

URL routes have a fairly simple syntax and are based on Lua's string.find, so see Lua patterns documentation if you need to write complicated routes.

You can write normal text: /hello/world

You can use named parameters /hello/:name

(Which will match anything up to the next /.

And you can match patterns: /hello/<name:%a%w*>

There are also two built-in patterns for convenience, identifier and int

You can use them like so: /birthday/<name:identifier>/<age:int>

Which is the same as: /birthday/<name:%a%w*>/<age:%d+>

heart.app

heart.app() returns a new application - a table whose methods you use to create your application. Note that it is also a callable function that can be passed to http.createServer, and can also be wrapped in middleware if you so desire.

serve_file(path : string)

Serve a static file as a response.

static(dir: string)

A utility handler that will serve up static files within a directory. Use it like so, and don't append a slash to the directory:

app.get('/static/<path:.+>', heart.static('./static'))

application members

default_content_type : string = "text/html"

Change the assumed content type of strings returned by handlers. Useful if you wanted to make, for instance, a JSON app.

not_found : function(req)

Called when 404 errors are encountered to give a descriptive error message

get(route : string, handler : function(req, res))
post(route : string, handler : function(req, res))

Handle requests that match ROUTE with handler.

log : function(...)

Prints a bunch of stuff to stdout. If you like, you can replace it with a no-op or integrate your own logs.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].