{"id":13316225,"url":"https://github.com/upvalue/luvit-heart","last_synced_at":"2025-07-25T02:32:03.168Z","repository":{"id":8617491,"uuid":"10259478","full_name":"upvalue/luvit-heart","owner":"upvalue","description":"A micro web framework for Luvit","archived":false,"fork":false,"pushed_at":"2013-05-25T04:31:34.000Z","size":144,"stargazers_count":15,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-15T01:53:06.517Z","etag":null,"topics":["luvit","web-framework"],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/upvalue.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-05-24T04:53:02.000Z","updated_at":"2023-12-17T19:31:06.000Z","dependencies_parsed_at":"2022-08-27T09:02:11.305Z","dependency_job_id":null,"html_url":"https://github.com/upvalue/luvit-heart","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/upvalue/luvit-heart","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upvalue%2Fluvit-heart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upvalue%2Fluvit-heart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upvalue%2Fluvit-heart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upvalue%2Fluvit-heart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/upvalue","download_url":"https://codeload.github.com/upvalue/luvit-heart/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upvalue%2Fluvit-heart/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266944274,"owners_count":24010485,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["luvit","web-framework"],"created_at":"2024-07-29T18:20:37.711Z","updated_at":"2025-07-25T02:32:02.894Z","avatar_url":"https://github.com/upvalue.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"Heart is a micro web framework for [luvit](http://luvit.io). It basically just dispatches URLs and provides a\nlittle sugar for dealing with HTTP requests and responses. Templates, sessions, and so forth are entirely up to you.\n\nReleased under the [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)\n\n### Using\n\nIn your project directory:\n\u003e mkdir -p modules/\n\n\u003e git clone git://github.com/ioddly/luvit-heart.git modules/heart\n\nThen create, say, main.lua\n\n```lua\nlocal app = require('heart').app()\n\napp:get('/', function()\n  return 'Hello, world!'\n)\n\nrequire('http').createServer(app):listen(8080)\n```\n\nHeart is definitely a little more verbose and explicit than Ruby micro frameworks. I like it that way. I've also tried\nnot to add too much sugar, in case luvit ever gets a consensus middleware system like Rack.  See sample.lua for a more\ncomplex example.\n\n### Documentation\n\n##### Writing handlers\n\nHandlers take the same arguments as the http.createServer callback does: req and res. See the luvit documentation for\ndetails on those objects (or the node.js documentation which is mostly the same).\n\nreq has an additional field added: heart, which contains any parameters given in the URL. For instance, if your route\nis /hello/:name, you can access name in your handler through req.heart.params.name\n\nOnce your handler is finished doing whatever it needs to do, you should return your response values. The simplest way\nto 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.\n\nHowever, if you need to do more with http response codes, you can redirect stuff\n\n```lua\nreturn 301, '/new_url'\n```\n\nReturn response codes\n```lua\nreturn 500, 'Server Error'\n```\nOr even return a code, body, and headers\n```lua\nreturn 500, 'Server Error', { ['Imaginary-Header'] = \"It's late and I can't think up a header example\" }\n```\n\nFinally, if you need to do something wacky with the response object (such as fire off a callback that will stream a file\nasynchronously), return 0 and heart will not send a response.\n\n##### URL Routing\n\nURL routes have a fairly simple syntax and are based on Lua's string.find, so see Lua patterns documentation if you need\nto write complicated routes.\n\nYou can write normal text: ```/hello/world```\n\nYou can use named parameters ```/hello/:name```\n\n(Which will match anything up to the next /. \n\nAnd you can match patterns: ```/hello/\u003cname:%a%w*\u003e ```\n\nThere are also two built-in patterns for convenience, identifier and int\n\nYou can use them like so:  ```/birthday/\u003cname:identifier\u003e/\u003cage:int\u003e```\n\nWhich is the same as: ```/birthday/\u003cname:%a%w*\u003e/\u003cage:%d+\u003e```\n\n##### heart.app\n\nheart.app() returns a new application - a table whose methods you use to create your application. Note that it is also\na callable function that can be passed to http.createServer, and can also be wrapped in middleware if you so desire.\n\n##### serve_file(path : string)\n\nServe a static file as a response.\n\n##### static(dir: string)\n\nA utility handler that will serve up static files within a directory. Use it like so, and don't append a slash to the\ndirectory:\n\n```lua\napp.get('/static/\u003cpath:.+\u003e', heart.static('./static'))\n```\n\n#### application members\n\n##### default_content_type : string = \"text/html\"\n\nChange the assumed content type of strings returned by handlers. Useful if you wanted to make, for instance, a JSON\napp.\n\n##### not_found : function(req)\n\nCalled when 404 errors are encountered to give a descriptive error message\n\n##### get(route : string, handler : function(req, res))\n##### post(route : string, handler : function(req, res))\n\nHandle requests that match ROUTE with handler.\n\n##### log : function(...)\n\nPrints a bunch of stuff to stdout. If you like, you can replace it with a no-op or integrate your own logs.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fupvalue%2Fluvit-heart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fupvalue%2Fluvit-heart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fupvalue%2Fluvit-heart/lists"}