All Projects → tipsy → Javalin

tipsy / Javalin

Licence: apache-2.0
A simple and modern Java and Kotlin web framework

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects
HTML
75241 projects
Vue
7211 projects
javascript
184084 projects - #8 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to Javalin

Proteus
Lean, mean, and incredibly fast JVM framework for web and microservice development.
Stars: ✭ 178 (-96.57%)
Mutual labels:  rest-api, microservice, web-framework
Clevergo
👅 CleverGo is a lightweight, feature rich and high performance HTTP router for Go.
Stars: ✭ 246 (-95.25%)
Mutual labels:  rest-api, web-framework
Frappe
Low code web framework for real world applications, in Python and Javascript
Stars: ✭ 3,349 (-35.4%)
Mutual labels:  rest-api, web-framework
Jupiter
Jupiter是斗鱼开源的面向服务治理的Golang微服务框架
Stars: ✭ 3,455 (-33.35%)
Mutual labels:  microservice, web-framework
Kratos
A modular-designed and easy-to-use microservices framework in Go.
Stars: ✭ 15,844 (+205.63%)
Mutual labels:  rest-api, microservice
Mcloud
基于Spring Cloud,实现微服务中常用的基础模块,包括 OAuth2 认证服务,统一注册中心,系统监控中心, 统一配置中心,API网关以及熔断器
Stars: ✭ 185 (-96.43%)
Mutual labels:  rest-api, microservice
Hunt Framework
A Web framework for D Programming Language. Full-stack high-performance.
Stars: ✭ 256 (-95.06%)
Mutual labels:  microservice, web-framework
Kotlin Spring Boot Jpa Rest Api Demo
Build a Restful API with Kotlin, Spring Boot, Mysql, Jpa and Hibernate
Stars: ✭ 67 (-98.71%)
Mutual labels:  rest-api, microservice
Kanary
A minimalist web framework for building REST APIs in Kotlin/Java.
Stars: ✭ 319 (-93.85%)
Mutual labels:  rest-api, microservice
Gramework
Fast and Reliable Golang Web Framework
Stars: ✭ 354 (-93.17%)
Mutual labels:  rest-api, web-framework
Echo
High performance, minimalist Go web framework
Stars: ✭ 21,297 (+310.82%)
Mutual labels:  microservice, web-framework
Appkernel
API development made easy: a smart Python 3 API framework
Stars: ✭ 152 (-97.07%)
Mutual labels:  rest-api, microservice
Gemini
Model Driven REST framework to automatically generate CRUD APIs
Stars: ✭ 138 (-97.34%)
Mutual labels:  rest-api, microservice
Go Codon
Workflow based REST framework code generator
Stars: ✭ 133 (-97.43%)
Mutual labels:  rest-api, web-framework
Bk Cmdb
蓝鲸智云配置平台(BlueKing CMDB)
Stars: ✭ 4,269 (-17.65%)
Mutual labels:  rest-api, microservice
skinny-micro
🎤 Micro Web framework to build Servlet applications in Scala, the core part of Skinny Framework 2
Stars: ✭ 57 (-98.9%)
Mutual labels:  web-framework, jetty
Server
Serve your Rubix ML models in production with scalable stand-alone model inference servers.
Stars: ✭ 30 (-99.42%)
Mutual labels:  rest-api, microservice
Cakephp
CakePHP: The Rapid Development Framework for PHP - Official Repository
Stars: ✭ 8,453 (+63.06%)
Mutual labels:  rest-api, web-framework
Jetty.project
Eclipse Jetty® - Web Container & Clients - supports HTTP/2, HTTP/1.1, HTTP/1.0, websocket, servlets, and more
Stars: ✭ 3,260 (-37.11%)
Mutual labels:  servlet, jetty
Xsbt Web Plugin
Servlet support for sbt
Stars: ✭ 381 (-92.65%)
Mutual labels:  servlet, jetty

Chat at https://discord.gg/sgak4e5NKv Chat at https://gitter.im/javalin-io/general CI License Maven

Javalin - A simple web framework for Java and Kotlin

Javalin is a very lightweight web framework for Kotlin and Java which supports WebSockets, HTTP2 and async requests. Javalin’s main goals are simplicity, a great developer experience, and first class interoperability between Kotlin and Java.

Javalin is more of a library than a framework. Some key points:

  • You don't need to extend anything
  • There are no @Annotations
  • There is no reflection
  • There is no other magic; just code.

General information:

Quickstart

Add dependency

Maven

<dependency>
    <groupId>io.javalin</groupId>
    <artifactId>javalin</artifactId>
    <version>4.1.1</version>
</dependency>

Gradle

implementation "io.javalin:javalin:4.1.1"

Start programming (Java)

import io.javalin.Javalin;

public class HelloWorld {
    public static void main(String[] args) {
        Javalin app = Javalin.create().start(7000);
        app.get("/", ctx -> ctx.result("Hello World"));
    }
}

Start programming (Kotlin)

import io.javalin.Javalin

fun main() {
    val app = Javalin.create().start(7000)
    app.get("/") { ctx -> ctx.result("Hello World") }
}

Examples

This section contains a few examples, mostly just extracted from the docs. All examples are in Kotlin, but you can find them in Java in the documentation (it's just syntax changes).

Api structure and server config

val app = Javalin.create { config ->
    config.defaultContentType = "application/json"
    config.autogenerateEtags = true
    config.addStaticFiles("/public")
    config.asyncRequestTimeout = 10_000L
    config.dynamicGzip = true
    config.enforceSsl = true
}.routes {
    path("users") {
        get(UserController::getAll)
        post(UserController::create)
        path(":user-id") {
            get(UserController::getOne)
            patch(UserController::update)
            delete(UserController::delete)
        }
        ws("events", userController::webSocketEvents)
    }
}.start(port)

WebSockets

app.ws("/websocket/:path") { ws ->
    ws.onConnect { ctx -> println("Connected") }
    ws.onMessage { ctx ->
        val user = ctx.message<User>(); // convert from json string to object
        ctx.send(user); // convert to json string and send back
    }
    ws.onClose { ctx -> println("Closed") }
    ws.onError { ctx -> println("Errored") }
}

Filters and Mappers

app.before("/some-path/*") { ctx ->  ... } // runs before requests to /some-path/*
app.before { ctx -> ... } // runs before all requests
app.after { ctx -> ... } // runs after all requests
app.exception(Exception.class) { e, ctx -> ... } // runs if uncaught Exception
app.error(404) { ctx -> ... } // runs if status is 404 (after all other handlers)

app.wsBefore("/some-path/*") { ws ->  ... } // runs before ws events on /some-path/*
app.wsBefore { ws -> ... } // runs before all ws events
app.wsAfter { ws -> ... } // runs after all ws events
app.wsException(Exception.class) { e, ctx -> ... } // runs if uncaught Exception in ws handler

JSON-mapping

var todos = arrayOf(...)
app.get("/todos") { ctx -> // map array of Todos to json-string
    ctx.json(todos)
}
app.put("/todos") { ctx -> // map request-body (json) to array of Todos
    todos = ctx.body<Array<Todo>>()
    ctx.status(204)
}

File uploads

app.post("/upload") { ctx ->
    ctx.uploadedFiles("files").forEach { (contentType, content, name, extension) ->
        FileUtil.streamToFile(content, "upload/$name")
    }
}

OpenAPI (Swagger)

Javalin has an OpenAPI (Swagger) plugin. Documentation can be enabled both through a DSL and through annotations, and Javalin can render docs using both SwaggerUI and ReDoc. Read more at https://javalin.io/plugins/openapi.

Special thanks

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].