Coder Social home page Coder Social logo

pappel-framework's Introduction

Pappel Framework

A Kotlin framework for Node.js applications

Features

  • Clean and well-typed API
  • Full MVC support
  • Powered by popular node modules (express, sequelize, โ€ฆ)
  • async/await language support
  • Mustache template engine
  • Built-in React support
  • Scalable complexity including stackable applications

Example code

Routing

import pappel.Router

class Router : Router() {

    /**
     * Initialize routes
     */
    init {

        /**
         * Render Hello World on /
         */
        get("/") {
            _, response ->
            response.send("Hello world")
        }

        /**
         * Render JSON output on /json
         */
        get("/json") {
            _, response ->
            response.sendJSON(
                    arrayOf(1, 2, "test", mapOf("foo" to "bar")) as Array<Any?>
            )
        }

        /**
         * Render view using parameters on /view
         */
        get("/view") {
            request, response ->
            response.render("view", mapOf("path" to request.path) as Map<String, Any>)
        }

        /**
        * Handle request parameter 
        */
        get("/param/:id") {
            request, response ->
            response.send("Parameter id was ${request.parameters!!["id"]}")
        }
    }
}

Database and async/await support

async {
    await { db.connect() }

    await { model.user.sync(true) }

    val user = model.user.new()
    user1.username = "demo"

    await { model.user.save(user) }
}

Templates

<html>
    <head></head>
    <body>
        <p>Request on path {{path}}</p>
    </body>
</html>

React components

class CounterComponent : Component<Component.Props, CounterComponent.State>() {

    init {
        state = State(counter = 0)
    }

    override fun ReactDOMBuilder.render() {
        div("counter") {
            p {
                +"Counter: ${state.counter}"
            }
            button {
                +"Increase"

                onClickFunction = {
                    setState {
                        counter = state.counter + 1
                    }
                }
            }
        }
    }

    companion object : ReactComponentSpec<CounterComponent, Component.Props, CounterComponent.State>

    class State(var counter: Int = 0) : Component.State()
}

Disclaimer

Pappel framework is still under development and not yet ready to use as many features are still missing and the API may significantly change in the future.

If you're interested in updates or would like to support Pappel framework in any way, do not hesitate to get in touch.

pappel-framework's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

wadejensen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.