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/06/2018, 11:03 AM
    @RichyHBM here's the deck: https://speakerdeck.com/daviddenton/server-as-a-function-in-kotlin still no sign of the video - think that'll be a few weeks as they edit them together
    👍 1
    x
    • 2
    • 1
  • x

    xuemin.guan

    10/23/2018, 10:21 AM
    hi, we were recommended by our OPs to expose our metrics on a different port from our app’s main HTTP server. I wonder if there is a way in http4k do so, ie expose a RoutingHttpHandler on a different port from the app?
    a
    d
    • 3
    • 11
  • s

    s4nchez

    10/29/2018, 4:05 PM
    @natpryce how complicated does it need to be?
    n
    d
    • 3
    • 7
  • d

    dave

    10/30/2018, 9:07 AM
    @RichyHBM upgrading (to 1.3) in version 3.96.0 is on it's way.
    • 1
    • 1
  • d

    dave

    11/12/2018, 11:12 AM
    @Xavier Hanin that's awesome! hope it went well. Even though my french is appalling, I'll be watching this... 🙂
    x
    • 2
    • 1
  • x

    xuemin.guan

    11/23/2018, 10:51 AM
    hi @dave, would you mind to share some code to illustrate it? We got it working, but we fear it is not idiomatic. BTW, we registered com.fasterxml.jackson.datatype.joda.JodaModule
    • 1
    • 1
  • d

    dave

    11/23/2018, 1:01 PM
    @David Hamilton you can easily mount an http4k app alongside another servlet using the HttpHandler.asServlet() extension function. If you look at the
    Jetty
    object you can see the pattern for how this can be done using an embedded Jetty backend
    d
    • 2
    • 3
  • s

    s4nchez

    11/25/2018, 12:13 PM
    @David Hamilton Here's an example of how to combine list of filters in a functional fashion:
    val defaultStack = Filter.NoOp.then(ClientFilters.GZip())
    
        val additionalFilters: List<Filter> = listOf(
            DebuggingFilters.PrintRequestAndResponse(),
            ClientFilters.BasicAuth("user", "pass"))
    
        // additional after default
        val combinedFilter1: Filter = additionalFilters.fold(defaultStack) { acc, next -> acc.then(next) }
        
        // additional before default
        val combinedFilter2: Filter = additionalFilters.fold(Filter.NoOp) { acc, next -> acc.then(next) }.then(defaultStack)
    d
    d
    • 3
    • 3
  • d

    dave

    11/29/2018, 3:38 PM
    you'd end up with
    {
      "in": "body",
      "name": "body",
      "required": true,
      "schema": {
        "$ref": "#/definitions/someOtherDefinitionId"
      },
      "description": "the body of the message"
    }
    r
    • 2
    • 8
  • d

    dave

    12/06/2018, 6:55 AM
    @xuemin.guan easiest thing is to compose 2 modules together (each with a different root context).
    x
    • 2
    • 1
  • f

    fredrik.nordin

    12/06/2018, 9:33 AM
    @dave @s4nchez Huge kudos to both of you for adding the
    cloudnative
    module! Looks great and exactly what was needed for http4k to be a real contender for writing all my k8s hosted services 👏
    🙂 1
    d
    • 2
    • 11
  • s

    s4nchez

    12/06/2018, 11:42 AM
    @xuemin.guan are you able to send the headers the server is sending back? My first guess is that you have the filter being applied twice, hence duplicating the header, but it's hard to tell without looking at how things are setup on you side.
    x
    j
    d
    • 4
    • 19
  • r

    reik.schatz

    12/07/2018, 2:35 PM
    just curious, is there a filter similar to
    RequestTracing
    but using Opencensus?
    d
    • 2
    • 2
  • t

    tryge

    12/11/2018, 1:03 PM
    Hi everyone, is there a way to stream body payload on the server side, or at least restrict its size to a same limit without reading it into memory?
    d
    • 2
    • 22
  • c

    Codecraig

    12/12/2018, 12:41 PM
    Hi, I read that http4k can generate JSON Schema models (https://www.http4k.org/guide/modules/contracts/) ...is there an example/tutorial for that?
    d
    • 2
    • 8
  • d

    dave

    12/12/2018, 5:31 PM
    but it's possibly pretty expensive way to operate without a discriminating value
    x
    • 2
    • 1
  • a

    alieksie

    12/18/2018, 1:56 PM
    Hi http4k! Is it possible to have optional path segment? Like:
    "/bar/" / Path.string().of(name = "foo")
    comes
    "/bar/" / Path.string().of(name = "foo").optional
    So it would match both
    /bar/foo
    and
    /bar/
    r
    d
    • 3
    • 6
  • a

    Albert

    01/02/2019, 12:48 PM
    I am looking at the nonblocking, but I am not sure how to test this. according to https://www.http4k.org/cookbook/websockets/ you can do
    testApp.testWsClient
    but I need something like
    testApp.testWebsocket
    d
    • 2
    • 9
  • d

    dave

    01/30/2019, 5:19 PM
    this was missing from the docs - I'll stick this example on the site later
    x
    • 2
    • 1
  • d

    DALDEI

    01/30/2019, 7:58 PM
    I wanted to mention ( as most comments tend to be focused on issues/problems rather then whats NOT a problem) I find the entire http4k project quite exemplary in both function and style/form. At first glance (long time ago) my impression was that it must be deficient because the the code-base was too small and the style - simple and elegant -- to the point I was skeptical it would actually work in 'the real world' I have verified to my satisfaction that I was totally wrong. The apparent simplicity is actually elegance -- a direct representative of the overall design architecture. So much so that I still have a hard time figuring out how to use it -- it is so different form 'conventional' style/architecture that my instincts of where and what to look for are worthless I dont know what to suggest or how exactly to improve that -- just a comment that it is difficult to grasp how to use the various pieces and how they fit together -- because it was designed and implemented so well -- but differently -- I will speculate many people have a hard time 'Seeing the Obvious' -- I do ... but when I do -- its worth it> So thank you -- not just for a great library but also an inspiration and example of excellent engineering we could all strive to follow as a model of something done well.
    💯 5
    😊 3
    ➕ 2
    d
    s
    • 3
    • 4
  • x

    Xavier Hanin

    01/31/2019, 8:43 AM
    So we’d need the body lens to use a mapper configured specifically for the route, not for the whole application
    d
    • 2
    • 6
  • n

    natpryce

    01/31/2019, 10:26 AM
    What animal would you want on the cover?
    j
    d
    • 3
    • 2
  • d

    dave

    01/31/2019, 10:52 AM
    @Xavier Hanin thanks for posting that. I'll take a look and see if we can merge that method into the Jackson module.
    x
    • 2
    • 2
  • d

    dave

    02/01/2019, 10:39 AM
    @Xavier Hanin I've released v3.111.0 to maven with the view support in it. You can use the following form to create a lens with the view:
    Body.autoView<ArbObjectWithView, Public>().toLens()
    x
    • 2
    • 1
  • d

    dave

    02/12/2019, 7:24 PM
    @Xavier Hanin Np. Thanks for the PR! Although lets not belittle my effort of typing
    release.sh 3.112.2
    🐿 2
    😁 1
    👏 2
    j
    • 2
    • 1
  • s

    sahil Lone

    02/18/2019, 8:42 AM
    Hello Everyone. I am trying Http4k for a project. Have a doubt in my mind which I couldn't find in docs. 1. How is blocking code handled in Http4k. 2. What's the relation b/w a request and thread when I am using Netty. 3. Is there a construct provided by the http4k to execute asynchronous blocking and non-blocking calls.
    f
    d
    • 3
    • 16
  • d

    dave

    03/10/2019, 4:47 PM
    Hey peeps. Bit of an FYI about an API change. As a part of
    v3.116.0
    that we've just released, we've introduced a better API for
    http4k-contract
    which is more consistent with the way we define
    route
    meta. It looks like this:
    val router = "/basepath" bind contract {
        renderer = SimpleJson(Jackson)
        descriptionPath = "/swagger.json"
        security = ApiKey(Query.required("the_api_key"), { true })
        routes += "/descriptions" meta {
            summary = "endpoint"
            description = "some rambling description of what this thing actually does"
            operationId = "echoMessage"
            tags += Tag("tag1")
            queries += Query.boolean().required("b", "booleanQuery")
            receiving(Body.json("json").toLens())
        } bindContract GET to { Response(OK) }
    }
    We've deprecated the old
    contract()
    functions for the time being - they were getting a little out of hand with 8 or so overloaded (and all defaulted anyway) args, hence this change. Have a play and let us know if you like/hate it. Also in this release, there's a new
    http4k-template-freemarker
    module. 🙄
    👍 2
    f
    • 2
    • 3
  • d

    dave

    03/25/2019, 8:17 AM
    @krtko yep - we already build http4k against java 11 and my current project is also happily using Java 11 in prod. We're also using Google Jib, which is pretty cool for building efficiently sized docker images straight from Gradle. https://github.com/GoogleContainerTools/jib
    k
    • 2
    • 3
  • d

    dave

    03/27/2019, 2:14 PM
    @tom_barnsbury I think they should be just as discoverable in the IDE - maybe I'm wrong? As for the extension vs member thing, it's a stylistic thing about what felt right when I wrote it. here's the code to explain a bit:
    interface Approver {
        fun <T : HttpMessage> assertApproved(httpMessage: T)
    }
    
    fun Approver.assertApproved(response: Response, expectedStatus: Status) =
        assertApproved(response.apply { assertEquals(expectedStatus, response.status) })
    
    fun <T : HttpMessage> Approver.hasApprovedContent(): Matcher<T> = ...
    The interface method is generified by HttpMessage, so for the first extension to be specific to
    Response
    felt a little wrong. The second was specific to hamkrest, which is totally outside the remit of the actual interface. On top of that, we don't even ship hamkrest with the module, so whilst convienient, it's even further away conceptually from the main interface.
    t
    • 2
    • 3
  • d

    dave

    03/28/2019, 5:21 AM
    @krtko for that you should use a Filter and just wrap your handler (or entire app) using
    then()
    . We provide the one below which should give you a general idea, but you can easily write your own to plug in whatever logger you need:
    object CatchAll {
            operator fun invoke(errorStatus: Status = INTERNAL_SERVER_ERROR): Filter = Filter { next ->
                {
                    try {
                        next(it)
                    } catch (e: Exception) {
                        val sw = StringWriter()
                        e.printStackTrace(PrintWriter(sw))
                        Response(errorStatus).body(sw.toString())
                    }
                }
            }
        }
    k
    • 2
    • 3
Powered by Linen
Title
d

dave

03/28/2019, 5:21 AM
@krtko for that you should use a Filter and just wrap your handler (or entire app) using
then()
. We provide the one below which should give you a general idea, but you can easily write your own to plug in whatever logger you need:
object CatchAll {
        operator fun invoke(errorStatus: Status = INTERNAL_SERVER_ERROR): Filter = Filter { next ->
            {
                try {
                    next(it)
                } catch (e: Exception) {
                    val sw = StringWriter()
                    e.printStackTrace(PrintWriter(sw))
                    Response(errorStatus).body(sw.toString())
                }
            }
        }
    }
k

krtko

03/28/2019, 4:38 PM
Thanks so if I wanted to add some general headers onto all of my responses, using a filter would be the route to go?
d

dave

03/28/2019, 4:39 PM
yep
k

krtko

03/28/2019, 4:40 PM
Thank you
View count: 7