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
  • u

    Uberto Barbini

    11/28/2019, 9:35 AM
    To be completely fair, for what we do (simple tables without joins between them) JOOQ is an overkill and IntelliJ Sql support is great. Still it would be nice to have a sensible Kotlinesque wrap around JDBC api... 🙂
    👍 1
    e
    • 2
    • 1
  • r

    Razi Kheir

    12/04/2019, 1:49 AM
    Hey @dave For some reason this snippet of code is not compiling for me, it fails the += operator. I am using it from: https://www.http4k.org/cookbook/typesafe_http_contracts/
    "Unresolved reference. None of the following candidates is applicable because of receiver type mismatch"
    I wonder if the issue is me injecting also other things into the handler that returns an HttpHandler
    d
    • 2
    • 9
  • a

    andyg

    12/17/2019, 1:21 AM
    thanks @dave. started playing around a bit and I see those methods, however I don't see how to turn the resulting string back into a new Request. I also note there is
    toCurl()
    which might be even more useful, given that Curl clearly identifies headers, form fields, etc with
    -H
    ,
    --data
    , etc. Plus Curl is a universal spec, a quick search shows a number of Curl to XXX interpreters in various languages.
    d
    • 2
    • 4
  • j

    James Richardson

    01/10/2020, 7:22 AM
    Agreed on the oa2/oa3 but you cant control what somebody else gives you...
    d
    • 2
    • 2
  • r

    RichyHBM

    01/12/2020, 1:40 PM
    Should the hot reload base sir be sec/main/resources?
    d
    • 2
    • 2
  • j

    James Shiell

    01/16/2020, 1:36 PM
    Hmm. Musing for you -
    ClientFilters.Gzip
    currently compresses the request, and decompresses the response. Which is great, but request compression is pretty esoteric (as you can't guarantee the remote end will support it). Secondly, I don't see us setting an
    accept-encoding:gzip
    on the request, which means we shouldn't expect to get GZip back. As such, I suggest two changes (i.e. I'm happy to do it, but need a sanity check) a) Change
    ClientFilters.Gzip
    to set
    accept-encoding:gzip
    on request, but not to compress the request b) Add a new
    ClientFilters.RequestCompressingGzip
    to do the above, and additionally compress the request Seem fair? Or am I being daft?
    s
    • 2
    • 4
  • r

    Razi Kheir

    01/20/2020, 5:41 AM
    @dave I’m running into a similar issue that was resolved in 3.193.1, where specifying an optional in an a environment lens throws exception in runtime. Only this time it’s happening in a composite environment object. Version Used: 3.193.1
    Caused by: org.http4k.lens.LensFailure: location 'NON_OPTIONAL_VAR' must be object
    	at org.http4k.lens.Lens.invoke(lens.kt:17)
    	at config.CompositeEnvironmentHandler$$special$$inlined$composite$1.invoke(lensSpec.kt:262)
    	at config.CompositeEnvironmentHandler$$special$$inlined$composite$1.invoke(lensSpec.kt)
    	at org.http4k.lens.LensGet$invoke$1.invoke(lensSpec.kt:15)
    	at org.http4k.lens.LensGet$invoke$1.invoke(lensSpec.kt:14)
    	at org.http4k.lens.LensSpec$required$1.invoke(lensSpec.kt:99)
    	at org.http4k.lens.Lens.invoke(lens.kt:13)
    • 1
    • 1
  • d

    dave

    01/20/2020, 6:51 AM
    @Razi Kheir AFK, but at first glance it looks like you're not using the API quite correctly. Is there a reason you're not specifying the composite EnvironmentKey like the one in this test? https://github.com/http4k/http4k/blob/master/http4k-cloudnative/src/test/kotlin/org/http4k/cloudnative/env/EnvironmentKeyTest.kt
    r
    • 2
    • 9
  • d

    dave

    01/20/2020, 7:32 AM
    @Razi Kheir I've just rewritten the composite test to check that it works:
    @Test
        fun `composite can use a mixture of overridden and non overridden values`() {
            data class Target(val foo: String, val bar: Int, var foobar: Int?)
    
            val finalEnv = from("bar" to "123") overrides from("FOO" to "bill")
    
            val key = EnvironmentKey.composite {
                Target(
                    required("FOO")(it),
                    int().required("BAR")(it),
                    int().optional("FOOBAR")(it)
                )
            }
    
            assertThat(key(finalEnv), equalTo(Target("bill", 123, null)))
        }
    }
    😁 1
    r
    • 2
    • 5
  • r

    Razi Kheir

    01/24/2020, 6:42 AM
    Btw Is there a way to do nestable contract routes? I see nestable routes and contracts but I don’t see a way to do both?
    d
    • 2
    • 1
  • r

    Ray Eldath

    01/26/2020, 6:40 AM
    Hi everyone 😉 I know that http4k can generate
    responseLens
    and use
    returning
    to specify it in contract route. But I want to know is it possible to constraint and auto-marshalling for request? like
    data class LoginRequest(val email: String, val password: String) {
        init {
            require(EmailValidator.getInstance().isValid(email))
        }
    }
    
    val requestLens = Body.auto<LoginRequest>("Login essentials.")
    fun handler(login: LoginRequest): HttpHandler =  { req: Request -> ... }
    
    "/login" / Body.of(requestLens) meta {
       ...
    } bindContract <http://Method.POST|Method.POST> to ::handler
    Many thanks.
    d
    • 2
    • 2
  • r

    Ray Eldath

    01/27/2020, 5:25 AM
    ah, kinda disappointing... I now use
    jacksonObjectMapper().writeValueAsString(e)
    to manually convert the object, and it works fine now. i feel somewhat strange about the origin behavior. use
    writeValueAsString
    will format the stacktrace into a well-organized json but
    .with(error of e)
    will output the stacktrace solely which will crash the json parser. why
    with
    is designed to work in this way...? 😕
    d
    • 2
    • 13
  • a

    andyg

    01/29/2020, 3:17 AM
    Probably not http4k but... I built a JAR file using http4k w/embedded Undertow server. Deployed it behind an HAProxy load balancer. Currently just 1 instance, no SSL, just testing the connection. Works, but getting
    [XNIO-1 task-12] DEBUG <http://io.undertow.request.io|io.undertow.request.io> - UT005013: An IOException occurred
    <http://java.net|java.net>.SocketException: Connection reset
    immediately after every request. Have tried various HAProxy options but cannot fix.
    d
    j
    • 3
    • 7
  • s

    sp

    02/02/2020, 4:07 AM
    However, should clarify that the CORS error isn’t coming from http4k server which I fixed by adding the right CORS policy - it’s coming from github
    s
    • 2
    • 2
  • r

    Ray Eldath

    02/04/2020, 9:35 AM
    hey everyone. is there any way to mark a field as optional in auto-modeled http body message? like, define:
    data class ApproveRequest(val roleId: Int, val extraPermissions: List<InboundPermission> = emptyList())
    and
    private val requestLens = Body.auto<ApproveRequest>().toLens()
    want i want is the field
    extraPermissions
    will be marked as
    optional
    instead of
    required
    in generated OpenApi doc because it have a default value. this may seems somewhat unreasonable, but i just met this in my backend application 😅
    d
    • 2
    • 2
  • a

    andyg

    02/06/2020, 7:42 AM
    Hi, is there a noticable performance or resource penalty when adding websockets and using a PolyHandler? Any plans to add Undertow as a WsServer (currently only Jetty)? Still exploring all the features of http4k 🙂 Thanks!
    d
    • 2
    • 2
  • j

    Jordan Terrell

    02/07/2020, 2:06 PM
    I know this is everyone's "favorite" question, but are there any updates on async server support, either via coroutines or some other mechanism? Last mention of coroutines in this room (that I could find) was back in September, the GitHub issue was last updated in June, and the v4 Spike branch was last updated in October. Is anyone working on async server support or has that been put on hold?
    👍 1
    d
    s
    +3
    • 6
    • 12
  • j

    jh

    02/13/2020, 9:49 AM
    Hi! We are responding with an input stream from a temporary file on disk.
    Response(OK).body(tempFile.inputStream())
    Is there any way to detect when the response has been fully read so that we can then delete the temp file on disk?
    d
    t
    • 3
    • 7
  • m

    Mehdi

    02/14/2020, 11:47 PM
    Could anybody help that what is wrong with this code?
    val app = { request: Request -> Response(OK).body("Hello, ${request.query("name")}!") }
    
    val jettyServer = app.asServer(Jetty(9006)).start()
     val client = WebsocketClient.blocking(Uri.of("<wss://echo.websocket.org>"), headers = listOf(Pair("a header", "value")))
    
            
            client.send(WsMessage("hello"))
    
            // read all of the messages from the socket until it is closed (by the server).
            // we expect to get one message back before the stream is closed.
            client.received().toList().forEach(::println)
    I am able to connect but I am not receiving any message. I want to develop a websocket client always send and receive messages to/from the server
    d
    • 2
    • 14
  • a

    Anil

    02/27/2020, 4:28 PM
    Hi David, How to create custom JsonErrorResponseRenderer in OpenApi3 ?
    d
    • 2
    • 2
  • s

    s4nchez

    03/02/2020, 2:45 PM
    @Uberto Barbini We never got around implementing that parser because http4k itself doesn't tend to act based on content type, whereas applications do. Having a parser would be handy though and I'd be happy to incorporate a PR on that area.
    👍 2
    u
    n
    • 3
    • 2
  • s

    Sandra

    03/05/2020, 10:52 AM
    Generating API documentation with OpenApi3, how can I add a description to JSON schema properties? I tried @JsonPropertyDescription annotation but that doesn't work
    d
    • 2
    • 1
  • r

    Ray Eldath

    03/11/2020, 2:18 PM
    Hey everyone - currently I'm using micrometer & http4k-metrics for my metrics data collecting. i've noticed seems the default collecting interval is 10s, is there any way to change this interval? many thanks 😉
    d
    • 2
    • 1
  • e

    Emile Achadde

    03/19/2020, 3:51 PM
    @s4nchez I looked at the documents you provided and got lost ... I have to parse a string in json format like this one '{"name" : "some-name", "age": 30}" what is the simplest way to get "some-name" and 30 ?
    d
    • 2
    • 2
  • c

    Cosmin Victor Celea

    03/20/2020, 8:44 AM
    Does anyone have some hints on how to configure a server(JETTY) to require SSL in http4k?🆘 (edited)
    d
    a
    • 3
    • 2
  • e

    Emile Achadde

    03/23/2020, 11:06 AM
    I have a Kotlin code using http4k imports which provides running JVM executable suing gradle. Is there a way to make it provide JS executable ? It seems that kotlin(stdlib-js) does not resolve any of the http4k import. Did I miss to provide some gradle item ?
    s
    • 2
    • 2
  • d

    dave

    03/23/2020, 6:09 PM
    the default jetty implementation will not give you access to the certificates. If you really "need" the cert inside your app (rather than just rejecting requests without it), then I suggest using an RequestContext. OTOH, if you just want to reject, you can write a custom Jetty Handler which will do it and just handle it in that layer
    c
    • 2
    • 10
  • m

    Mehdi

    03/24/2020, 1:36 PM
    Could you please share a sample showing how to dockerify a http4k application?
    d
    a
    • 3
    • 3
  • s

    s4nchez

    03/27/2020, 10:18 AM
    @sahil Lone There's no need to define the
    /tokens
    path twice. This should work:
    class TokensRouter(private val tokensCommandHandler: TokensCommandHandler) {
        operator fun invoke(): RoutingHttpHandler =
            ServerFilters.Cors(CorsPolicy.UnsafeGlobalPermissive).then(routes(
                "/tokens" bind <http://Method.POST|Method.POST> to tokensCommandHandler::invoke
            ))
    }
    s
    • 2
    • 12
  • c

    Cosmin Victor Celea

    04/01/2020, 2:24 PM
    Hi @dave how would you handle sessions in http4k? I am trying to a simple string that should persist in the session
    d
    j
    • 3
    • 2
Powered by Linen
Title
c

Cosmin Victor Celea

04/01/2020, 2:24 PM
Hi @dave how would you handle sessions in http4k? I am trying to a simple string that should persist in the session
d

dave

04/01/2020, 2:26 PM
TBH, I've only ever stuck it in redis or encrypt it and stick it entirely into a cookie.
j

James Richardson

04/02/2020, 3:24 PM
Sessions as in maps of stuff that hang around in memory between request invocations are not very compatible with 12 factor apps, so probably not terribly common. You could probably hook up a filter and a RequestContext to create a session-like experience, but would definitely be careful there...
👍 1
View count: 5