complate-http4k

complate integration for HTTP4K

License

License

GroupId

GroupId

com.github.complate
ArtifactId

ArtifactId

complate-http4k
Last Version

Last Version

0.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

complate-http4k
complate integration for HTTP4K
Project URL

Project URL

http://github.com/complate/complate-http4k
Project Organization

Project Organization

com.github.complate
Source Code Management

Source Code Management

https://github.com/complate/complate-http4k

Download complate-http4k

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.complate/complate-http4k/ -->
<dependency>
    <groupId>com.github.complate</groupId>
    <artifactId>complate-http4k</artifactId>
    <version>0.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.complate/complate-http4k/
implementation 'com.github.complate:complate-http4k:0.1.1'
// https://jarcasting.com/artifacts/com.github.complate/complate-http4k/
implementation ("com.github.complate:complate-http4k:0.1.1")
'com.github.complate:complate-http4k:jar:0.1.1'
<dependency org="com.github.complate" name="complate-http4k" rev="0.1.1">
  <artifact name="complate-http4k" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.complate', module='complate-http4k', version='0.1.1')
)
libraryDependencies += "com.github.complate" % "complate-http4k" % "0.1.1"
[com.github.complate/complate-http4k "0.1.1"]

Dependencies

compile (2)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jre8 jar 1.1.51
org.http4k : http4k-core jar 2.35.1

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

complate HTTP4K Adapter

Build Status codecov License

This adapter connects HTTP4K with the templating engine complate.

Usage

Compiling and Installation

Unless this library becomes available via maven central (or others), it can be built and installed to the local maven repo:

./gradlew clean build
./gradlew install

Dependency

Library import:

dependencies {
  compile 'com.github.complate:complate-http4k:0.1.1'
}

HTTP4K Example

Everything that is required to move an existing HTTP4K based application from another templating engine towards complate can be achieved by switching the templates to com.github.complate.ComplateTemplates.

Here is a more-or-less complete (working) base that shows how to use.

dependencies {
  // Kotlin
  compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
  
  // HTTP4K
  compile "org.http4k:http4k-core:2.35.1"
  compile "org.http4k:http4k-server-netty:2.35.1"
  
  // complate Adapter
  compile 'com.github.complate:complate-http4k:0.1.1'
}
package com.github.complate.http4k.demo
  
import com.github.complate.ComplateTemplates
import org.http4k.core.Method
import org.http4k.core.Response
import org.http4k.core.Status
import org.http4k.routing.bind
import org.http4k.server.Http4kServer
import org.http4k.server.Netty
import org.http4k.server.asServer
import org.http4k.template.TemplateRenderer
import org.http4k.template.ViewModel
import kotlin.concurrent.thread
  
  
val bundles = "src/main/resources/frontend"
  
fun main(args: Array<String>) {
  val app = DemoApplication()
  app.start()
  Runtime.getRuntime().addShutdownHook(thread(start = false) { app.stop() })
}
  
data class Person(val name: String, val age: Int) : ViewModel
  
class DemoApplication {
  private val server: Http4kServer
  private val renderer: TemplateRenderer = ComplateTemplates().HotReload(bundles)
  
  private val routes = org.http4k.routing.routes(
    "/person" bind Method.GET to {
      val viewModel = Person("Bob", 45)
      val renderedView = renderer(viewModel)
      Response(Status.OK).body(renderedView)
    }
  )
  
  init {
    server = routes.asServer(Netty(9000))
  }
  
  fun start() = server.start()
    
  fun stop() = server.stop()
}

TODOs

Caching (file & class path) is not implemented at the moment:

class ComplateTemplates : Templates {
  override fun Caching(baseTemplateDir: String): TemplateRenderer {
    TODO("not implemented")
  }

  override fun CachingClasspath(baseClasspathPackage: String): TemplateRenderer {
    TODO("not implemented")
  }
}

This will hopefully added in a future version of the adapter (most likely v0.2.0).

com.github.complate

Versions

Version
0.1.1