https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
http4k
  • d

    dave

    10/30/2017, 1:52 PM
    @arocnies we've been having a nightmare with the tech empower results - we simply cannot reproduce their results locally - and we certainly see much better performance in our prod environments, which run in a completely unoptimized Jetty (apart from choice of GC). For the latest R15 preview 3 (if they ever get around to it!), I've stripped back the implementation to remove the database cases to see if that helps, but I'm not too hopeful TBH. At the very least, there shouldn't be much difference between the Jetty results and our Jetty server backend version - since we're just providing a very thin layer over the top of a servlet. We'll see what happens....
    😔 1
    j
    • 2
    • 1
  • d

    dave

    11/14/2017, 10:12 AM
    cool. thanks @ndchorley - keep plugging away and le tus know where the pain points are (if any!)! 🙂 In terms of a (planned) http4k-session module, I'm intending to provide an a. an interface for session persistence, and b. to use the Lens API to make the session management completely typesafe using SessionKey Lenses. This will make it consistent with the rest of the http4k APIs, so should fit in quite nicely. Now we just need the time (or volunteers) to do the dev work! 🙂
    n
    • 2
    • 1
  • g

    g4sarma

    01/15/2018, 4:39 PM
    Do you guys have any link or suggestion on some valuable resource for starters ?
    p
    • 2
    • 1
  • d

    dave

    01/15/2018, 8:54 PM
    @fredrik.nordin looks more like it 🙂 . it's obviously missing the request counter - not sure if you want to put that in as well if you're there? Also, I'm torn as to if to have MetricsFilters object, or to make the Filter creation methods extension methods on ServerFilters and ClientFilters (respectively). Raise the PR and I'll have a mull over that. 🙂
    f
    • 2
    • 4
  • d

    dave

    02/23/2018, 3:05 PM
    fun add(value1: Int, value2: Int): HttpHandler = {
            Response(OK).with(
                Body.string(TEXT_PLAIN).toLens() of (value1 + value2).toString()
            )}
    
        val contract = contract(OpenApi(ApiInfo("my great api", "v1.0"), Argo),
            "/add" / <http://Path.int|Path.int>().of("value1") / Path.fixed("hello") / <http://Path.int|Path.int>().of("value2") meta {
                summary = "add"
                description = "Adds 2 numbers together"
                returning("The result" to OK)
            } bindContract GET
                to { a, _, c -> add(a, c) }
        )
    
        contract.asServer(Jetty(8000)).start()
    e
    • 2
    • 22
  • d

    dave

    02/24/2018, 8:13 AM
    @scap one more thing - I've been thinking about is and think we might want to change the security filter order, so it runs the standard filter first, then Security, then an optional post security filter. This would allow things like auditing, monitoring and request context setup to happen first. It would be a breaking change to the API, but I think it's a much better model. Thoughts - or can anyone think of a case where this would be a bad thing?
    s
    • 2
    • 2
  • s

    scap

    02/27/2018, 4:46 AM
    @elifarley I too have notice this. I have just been living with it but would like to be able to name the object. I haven't found a way.
    e
    d
    • 3
    • 18
  • e

    elifarley

    03/02/2018, 1:54 PM
    FYI: New PR at https://github.com/http4k/http4k/pull/103 Motivation: JsonIter has a nice API, has lazy evaluation, and is faster than most other JSON libs. (See benchmarks at https://github.com/fabienrenaud/java-json-benchmark) I could simply add JsonIter to my project and use it, but then Http4K lib itself would still use another JSON lib, so I would end up having 2 JSON library dependencies. By having a JsonIter module, I can have only 1 JSON dependency, and as an added bonus, Http4K will use a faster JSON library 😉
    • 1
    • 1
  • e

    elifarley

    03/06/2018, 9:46 PM
    I have a
    class SimpleObject(val id: String, val attrs: Map<String, Any?>,
                            val created: ZonedDateTime,
                            val updated: ZonedDateTime
    )
    If I use
    with( Header.zonedDateTime().required("last-modified") of obj.created)
    , I end up with multiple attributes like
    "created":{"dateTime":{"date":{"year":2018,"month":3,...
    ). I think it should be a single String attribute, based on my understanding of
    this.map(ZonedDateTime::parse, DateTimeFormatter.ISO_ZONED_DATE_TIME::format)
    in file lensSpec.kt
    s
    • 2
    • 31
  • e

    elifarley

    03/07/2018, 6:16 PM
    On the generated Swagger API json file, I have a duplicate key in "definitions" :
    "object-1161328054": {
    			"type": "object",
    			"properties": {}
    		},
    		"object158819726": {
    			"type": "object",
    			"properties": {
    				"id": {
    					"type": "string"
    				},
    				"attrs": {
    					"$ref": "#/definitions/object-1161328054"
    				},
    				"created": {
    					"type": "string"
    				},
    				"updated": {
    					"type": "string"
    				}
    			}
    		},
    		"object-1161328054": {
    			"type": "object",
    			"properties": {}
    		},
    d
    • 2
    • 6
  • d

    dave

    03/09/2018, 6:51 AM
    Normally we bind inside a with method call. Try calling it with the parens instead of infixed?
    e
    • 2
    • 11
  • e

    elifarley

    03/09/2018, 10:37 AM
    I have an HttpHandler that is returning
    HTTP/1.1 400 body 'body' must be object
    This message is hiding an exception. How can I get hold of it? I have these filters:
    routes(
    "/sgzr/api/v1" bind Api.router(productService, orderService)
    ).let {
    DebuggingFilters.PrintRequestAndResponse()
                    .then(ServerFilters.Cors(CorsPolicy.UnsafeGlobalPermissive))
                    .then(ServerFilters.CatchAll())
                    .then(ServerFilters.CatchLensFailure)
                    .then(it)
    }
    d
    • 2
    • 29
  • d

    dave

    03/20/2018, 9:58 PM
    @scap not in the spec. Or in the next version... https://stackoverflow.com/questions/42335178/swagger-wildcard-path-parameters
    s
    • 2
    • 2
  • d

    dave

    03/28/2018, 4:35 PM
    After a bit of a struggle with maven central, we've released v3.22.2 of http4k. New in this release: - A new OAuth module http4k-security-oauth, allowing for super simple integration with OAuth providers. Including pre configured instances for popular services like Google, Dropbox and Auth0 - Rewrite of static resource loaders to remove dependencies on javax.activation - previously this broke when upgrading to java 9 and above - Squashed a weird header bug with the Apache client which broke f5 load balancers.
    👏 1
    e
    • 2
    • 3
  • d

    dave

    04/06/2018, 7:30 PM
    @elifarley Thanks for the PR - I've managed to fix it in a more generic way - you can now optionally provide a function when creating the
    CatchLensFailure
    to create a custom response. New method looks like this:
    ServerFilters.CatchLensFailure { lensFailure -> Response(OK).body(lensFailure.localizedMessage) }
    . Releasing in 3.23.0
    e
    • 2
    • 55
  • j

    joscha.alisch

    04/10/2018, 5:50 PM
    Thanks @dave! It’s as simple as this:
    import org.http4k.contract.*
    import org.http4k.core.*
    import org.http4k.format.Jackson
    import org.http4k.format.Jackson.auto
    import org.http4k.routing.bind
    import org.http4k.routing.routes
    import org.http4k.server.Jetty
    import org.http4k.server.asServer
    
    data class MyDataClass(val something: String)
    val requestBody = Body.auto<MyDataClass>().toLens()
    
    fun main(args: Array<String>) {
        routes(
            "/api" bind contract(OpenApi(ApiInfo("My great API", "v1.0"), Jackson),"/route" meta {
                body = requestBody
            } bindContract Method.GET to ::handler)
        ).asServer(Jetty(5000)).start()
    }
    
    fun handler(request: Request): Response {
        return Response(Status.OK)
    }
    gives me
    {
      “swagger” : “2.0",
      “info” : {
        “title” : “My great API”,
        “version” : “v1.0”,
        “description” : “”
      },
      “basePath” : “/”,
      “tags” : [ ],
      “paths” : {
        “/api/route” : {
          “get” : {
            “tags” : [ “/api” ],
            “summary” : “<unknown>“,
            “description” : null,
            “produces” : [ ],
            “consumes” : [ “application/json” ],
            “parameters” : [ {
              “in” : “body”,
              “name” : “body”,
              “description” : null,
              “required” : true,
              “type” : “object”
            } ],
            “responses” : { },
            “supportedContentTypes” : [ ],
            “security” : [ ]
          }
        }
      },
      “securityDefinitions” : { },
      “definitions” : { }
    }
    d
    • 2
    • 8
  • r

    RichyHBM

    04/25/2018, 6:28 PM
    Also, anyone recommend an form library that plays well with http4k?
    d
    • 2
    • 2
  • d

    dave

    04/25/2018, 7:46 PM
    @RichyHBM I generally default to handlebars, but would be interested to hear other opinions, or for libs that we could integrate with.
    n
    • 2
    • 3
  • d

    dave

    06/15/2018, 7:53 AM
    @maybetrinity The same goes for the regexes - we'll see what we can do to add some simpled Kotlin wrappers to make this easy. The only thing about regexes are that they are inherently one way. If might make more sense to wrap the strings in a microtype (ie a data class with one field) and handle the (de)marshalling inside the construction of that type.
    👍 1
    m
    • 2
    • 1
  • d

    dave

    06/20/2018, 9:16 AM
    We'd love to see if you manage to get it running - although beware that the netty implementation is the least mature of all the server backends. I've not used it in a prod environment myself - I generally default to Undertow,
    r
    • 2
    • 9
  • a

    andyD

    06/20/2018, 9:55 PM
    Hey, I think the docs here https://www.http4k.org/guide/modules/message_formats/ are incorrect as the latest version for Jackson is 3.28.0 according to https://search.maven.org/#search%7Cga%7C1%7Ca%3A%22http4k-format-jackson%22
    d
    • 2
    • 3
  • r

    RichyHBM

    06/21/2018, 7:58 PM
    I can do, for now it's here https://www.richyhbm.co.uk/posts/compiling-kotlin-netty-webapp-with-graalvm/
    👍 2
    f
    d
    • 3
    • 5
  • s

    s4nchez

    06/25/2018, 8:47 AM
    @zero.meta Actually, @dave reminded me that the correct format for the above example is
    /foo/{bar:.*}
    (the
    .
    is important ;))
    z
    d
    • 3
    • 5
  • d

    dave

    07/11/2018, 10:35 AM
    @pabl0rg just an update on the tech empower benchmarks... Your suggestion of swapping out handlebars for pebble has had a significant uptick in the performance of the fortunes test. Comparative results for JVM frameworks based on the latest run: Handlebars - 11th position - 167k requests served - 48% compared to top performer Pebble - 6th position - 225k requests served - 67% compared to top performer See the full set here: https://www.techempower.com/benchmarks/#section=test&amp;runid=898a9857-e2a6-472c-ac4e-f0d0c851af30&amp;hw=ph&amp;test=fortune&amp;l=xan3i3-1
    💪 8
    p
    • 2
    • 1
  • n

    napperley

    07/23/2018, 11:07 PM
    Would it be possible to use HTTP4K in a OpenFaaS (https://www.openfaas.com) template? I have a Kotlin JVM OpenFaaS template (https://github.com/napperley/openfaas-kotlin-templates/tree/kotlin-jvm/template/kotlin-jvm) that needs to be refactored to use a HTTP/S server to handle input/output. This template is partially based on the official OpenFaaS Java 8 template (https://github.com/openfaas/templates/tree/master/template/java8).
    s
    • 2
    • 2
  • d

    dave

    08/15/2018, 9:09 PM
    @elifarley thanks for the PR - we'll look at getting it in soon - we just want to be extra careful as we've had the opposite experience - servers rejecting host headers when there is a port set. Out of interest, what is the server that rejects it without the port?
    e
    • 2
    • 2
  • d

    dave

    08/21/2018, 1:12 PM
    @Xavier Hanin sure. http4k was developed as a personal side project (and then subsequently used on) the redevelopment of www.nature.com (a major scientific publisher- where it makes up the vast bulk of the micro-service backend infra, serving 10s of millions of hits per day from a cloud-based backend. The number of nodes of each service probably averages at 6 . You can see the alexa.com stats here (it's 810 in the Global ranking, 395 in China): https://www.alexa.com/siteinfo/nature.com I can't disclose the names of the banks unfortunately. Performance-wise, you can take a look at the latest tech-empower rankings to see how it compares (I've filtered here for JVM only): https://www.techempower.com/benchmarks/#section=test&amp;runid=06753cdf-6519-4569-b9ea-c3ca36c9b07d&amp;hw=ph&amp;test=fortune&amp;l=xan3i3-3
    👍 1
    x
    e
    • 3
    • 4
  • a

    Albert

    09/10/2018, 6:01 PM
    Just opened PR for http4k https://github.com/adhesivee/kotlin-oauth2-server/pull/20 (still need to update docs)
    d
    • 2
    • 1
  • d

    David Hamilton

    09/11/2018, 10:33 AM
    💡 Thanks!
    • 1
    • 1
  • d

    dave

    10/03/2018, 6:10 PM
    @… that sounds wrong. We'll look at fixing it up if it doesn't make sense- thanks for pointing it out. I'll also look at how we can answer your query re: the response schema
    x
    • 2
    • 1
Powered by Linen
Title
d

dave

10/03/2018, 6:10 PM
@… that sounds wrong. We'll look at fixing it up if it doesn't make sense- thanks for pointing it out. I'll also look at how we can answer your query re: the response schema
x

Xavier Hanin

10/04/2018, 10:18 AM
thanks! And have a good kotlin konf!
View count: 6