Inspiration

A close friend at Clarkson once mentioned the idea. This has the potential to become an intermediary for a smart-home system. People can use different devices to POST to a centralized webserver which can then run appropriate code (written in Lua) to do things such as write to a database or even talk to IOT devices.

What it does

Users are able to create different endpoints that run Lua they defined when a POST request is made.

For example, if I create a webhook with the slug factorial and the code:

-- defines a factorial function
function fact (n)
  if n == 0 then
    return 1
  else
    return n * fact(n-1)
  end
end

print(fact(5))

When I make a POST request to /factorial it will return 120.

https://www.lua.org/pil/1.html

How I built it

I used Ktor and Exposed. This is an exciting up-and-coming web framework written in Kotlin, which provides the safety of type-safe code in a very developer friendly language. Kotlin extension functions and lambdas are what makes a lot of this project possible. Unlike the ever popular Python, so much more of these tools "just work" out of the box and are easy to use and can automate away a lot of common pains.

Challenges I ran into

Trying to make a frontend is always a pain, and getting Monaco to cooperate was a bit of a pain. However, now that it works it is awesome because it is literally the editor from VSCode!

Accomplishments that I'm proud of

How manageable the backend code is. Exposed DAO makes working with the webhooks dead simple, and splitting Ktor route concerns into separate files really helps.

What I learned

Trying to get Monaco editor working without npm is annoying.

What's next for look

Sandboxing the Lua would be necessary if ever made public. Hence no current live demo, but it will run flawlessly locally or if deployed to Heroku with Heroku Postgres enabled and DATABASE_SSL_MODE=require in the environment variables.

Authentication would also be a nice feature, so only authorized users can create and call webhooks.

Statistics would also be an interesting feature to have.

While Bootstrap makes things easy and decent look, things could look nicer with more time.

Built With

Share this project:

Updates