https://kotlinlang.org logo
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
  • a

    andyg

    08/06/2020, 3:36 PM
    Can I ask a philosophical question @dave ? Why do Java/Kotlin http servers like http4k, ktor, vertx also include a client module? There's already mature, full featured, easy to use http clients -- okhttp or fuel or retrofit (a little different, but same idea) for example. Meanwhile Flask doesn't include a client, neither does Laravel or Express. Is it something about the JVM? Is it just because it's easy to rearrange HttpHandlers? Somehow the other day I thought of how different building an http4k server is from a Flask one and was curious why. Thanks.
    n
    d
    s
    • 4
    • 9
  • r

    Riku

    08/06/2020, 5:20 PM
    Going to start a new project with http4k soon and there was a hint in twitter a month or so ago that some sort of generator or template-y thing is in the works. Is that something that might be revealed soon or should i not hold m breath 😀?
    d
    • 2
    • 2
  • c

    Cosmin Victor Celea

    08/07/2020, 1:08 PM
    @dave is there a recommended production server? I remember seeing something, some time ago, about Undertow being recommended. Is that true? Any special reasons for it?
    d
    • 2
    • 3
  • d

    dave

    08/13/2020, 11:47 AM
    Hi everyone. JTLYK that (as promised) the first 2 parts of the http4k 2020 masterplan are now in place. We'll be announcing this stuff more formally in due course, but thought we'd give you all a sneak peek... 🙃 Firstly, we've done a complete rebrand of the website. Please check it out and DM us with any feedback (good or bad!). https://www.http4k.org Next, the http4k Toolbox CLI is also now available for installation through SDKman! and Brew, allowing you to: 1. Generate a custom ZIP with entire project contents, including build tooling and packaging 2. Generate http4k Servers, Clients and Models from an OpenAPI V2/3 specification 3. Generate Model Data Classes from JSON/YAML/XML documents. Installation instructions can be found here: https://www.http4k.org/installation/ More good stuff coming soon, including a website version of the Toolbox and the next major release (v4), where we'll be doing a bit of a spring clean on the codebase. We're also looking at ways of packaging educational content on the site, maybe screencasts or training etc. One final thing, we'd like to collect examples of success stories using http4k in the wild. If you're on a project or at a company who is using the library and would like to be featured, please let us know!
    ❤️ 5
    🙂 4
    🚀 5
    💪 5
    🎉 4
    c
    s
    • 3
    • 2
  • v

    Veeti Paananen

    08/17/2020, 8:57 AM
    I’m working on an old-fashioned server-side rendered app in http4k and need some sort of cookie based sessions. Did anybody come up with this yet before I roll my own?
    s
    • 2
    • 1
  • e

    Elizabeth Thomas

    08/17/2020, 8:49 PM
    Is there a way to publish percentiles from
    MetricFilters.Server.RequestTimer
    ? I seem to get only the
    count
    ,
    mean
    ,
    sum
    and
    upper
    fields from
    http.server.request.latency
    metric published using the
    RequestTimer
    metric filter.
    d
    • 2
    • 3
  • c

    Cosmin Victor Celea

    09/02/2020, 9:58 AM
    Hei, I get the following error when trying to define a endpoint that starts with a dynamic path. (Example:
    Path.of("system", "The target system ") / "/feed"
    .
    Exception in thread "main" java.lang.IllegalArgumentException: Fixed path segments cannot contain /. Use the "a / b" form.
    Any ideas?
    d
    • 2
    • 31
  • s

    s4nchez

    09/02/2020, 10:09 AM
    Are you referring to git tags? We don't use them to denote releases
    • 1
    • 1
  • z

    zero_coding

    09/02/2020, 12:50 PM
    Hi all Does it exist a sample, how to use OAuth with Keycloak?
    s
    • 2
    • 2
  • z

    zero_coding

    09/03/2020, 9:17 PM
    Does http4k handle requests async?
    n
    • 2
    • 1
  • c

    Cosmin Victor Celea

    09/09/2020, 10:23 AM
    Is it possible to exclude some of the endpoints from the OpenApi Specs? There are some internal endpoints, that I want to hide from the specs endpoint.
    d
    • 2
    • 37
  • d

    dave

    09/14/2020, 12:36 PM
    Which reminds me, we've just added a repo of self contained example projects which showcase the various features of http4k. If there's anything you'd like to see then please let us know! https://github.com/http4k/examples
    m
    • 2
    • 50
  • d

    dave

    09/16/2020, 5:43 AM
    Hi everyone! Reminder that we'll be hosting http4k office hours later today. As well as the usual stuff, we can talk about the various http4k posts across the internet in the last week, or about our plans for the new http4k-connect project which we started up this week. 🙃 Join us @ 4pm BST, 8am PDT, 5pm CEST via Zoom: https://t.co/kb7EcuVbvi Sli.do link for any questions and proposed topics: https://app.sli.do/event/kqabztdc/live/questions
    d
    • 2
    • 4
  • j

    James Richardson

    09/16/2020, 8:19 AM
    Also - (if this is a wishlist! ) - AWS XRay connector/collector for http4k or example.
    d
    • 2
    • 1
  • f

    fredrik.nordin

    09/16/2020, 8:48 AM
    Oh yes, some light-weight connectors for Google Cloud services would be great. Same reason as above, don't want to pull in a million Google libraries just to put a message on a queue or get a value out of Datastore.
    s
    • 2
    • 1
  • c

    Cosmin Victor Celea

    09/16/2020, 1:04 PM
    Is there a way to configure max requests simultaneously for Undertow?
    d
    • 2
    • 3
  • d

    dave

    09/16/2020, 3:21 PM
    apologies for anyone who got locked out of the http4k office hours thing - technical problems..
    r
    • 2
    • 2
  • m

    Mehdi

    09/21/2020, 2:06 PM
    I am wondering How can I pass Environment setting to a http4k application using gadlew?
    d
    • 2
    • 4
  • p

    pabl0rg

    09/21/2020, 9:43 PM
    Hi @dave after upgrading from http4k 3.251 to 3.252 (or beyond) i get 403 errors when my app receives the callback from an oauth provider. This happens using the Apache server. If I switch to Jetty or Netty, the 403 problem goes away. Is there something special I should configure when using the Apache server?
    d
    • 2
    • 8
  • d

    dave

    09/23/2020, 1:06 PM
    Erm no there isn't one actually. we use a custom version of CatchAll.
    c
    • 2
    • 8
  • r

    Rodrigo Navarro

    09/23/2020, 5:02 PM
    I am tring to implement an OAuth server by using http4k OAuthServer class. Every interface and method are quite clear, except the create access token one:
    fun create(
            clientId: ClientId,
            tokenRequest: AuthorizationCodeAccessTokenRequest,
            authorizationCode: AuthorizationCode
        ): Result<AccessToken, AuthorizationCodeAlreadyUsed>
    I need a way to associate the access token with the authenticated user here. I was thinking that I could use the requests contexts api to pass the logged user somehow, but this method doesn’t have access the request object. I don’t know if I am not seeing something obvious here, but I can’t find a way to implement this.
    s
    • 2
    • 4
  • d

    dave

    09/25/2020, 12:35 PM
    You can use a composite. Example here: https://www.http4k.org/cookbook/typesafe_http_requests_with_lenses/
    r
    • 2
    • 2
  • r

    Razvan

    09/26/2020, 3:39 PM
    Hi, getting started with http4k and have some troubles understanding some concepts. I try poking around but got stuck here. I want to get the code from a from posted:
    val codeField = FormField.required("code")
            val pageForm = Body
                    .webForm(Validator.Strict, codeField)
                    .toLens()
    
            val validForm = pageForm(request)
            val code = codeField(validForm)
    but when I call the api from a static JS fetch request I get a 500 error:
    org.http4k.lens.LensFailure: header 'content-type' is not acceptable
    for the last line of code. Why does it check the content-type header if it's a Body lens ? And how to get around with it ? the JS fetch request is:
    fetch{"/check", {
      method: "post",
      body: "code=XXXX"
    })
    tried with FormData and multipart got the same error.
    d
    • 2
    • 9
  • s

    sahil Lone

    10/08/2020, 6:20 AM
    Guys,  I had started a library last year to have a wrapper over Jackson for a type safe programming. Please have. a look at it, remarks are highly appreciated and. if you believe it can. be taken further please help to contribute https://github.com/sahlone/kson
    f
    • 2
    • 4
  • c

    Cosmin Victor Celea

    10/08/2020, 2:52 PM
    is there a way to get info like userAgent or ip? Or do you have to get that from a custom server implemetation?
    s
    • 2
    • 4
  • o

    obobo

    10/08/2020, 7:20 PM
    Hi, I've setup a small netty server in a project to serve prometheus scrapes. It works fine, but a little while after I hit the endpoint I start seeing
    2020-10-08T19:17:15.008682Z [WARN] An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception. exception_message=Connection reset by peer exception_name=java.io.IOException
    Is there something I can setup to avoid this stacktrace? I assume this is because of keepalive.
    d
    • 2
    • 3
  • r

    Razvan

    10/10/2020, 8:31 PM
    Hi, for a demo I wrote a test fonction about Lenses like this:
    @Test
        fun `Lens exemple`() {
    
            data class User(val name: String, val age: Int)
    
            val idLens = <http://Path.int|Path.int>().of("id")
            val jsonBody = Body.auto<User>().toLens()
    
            val user: HttpHandler = routes(
                "users/{id}" bind GET to { r: Request ->
                    jsonBody.inject(User("Tom", 30 + idLens.extract(r)), Response(OK))
                }
            )
    
            val responseOk = user(Request(GET, "users/2"))
            val resposeObject = jsonBody.extract(responseOk)
            resposeObject.age shouldBe 32
        }
    But I get a Parser error:
    Signature Parse error: expected '<' or ';' but got  
    	Remaining input:  exemple$User;>;
    If I move the
    User
    class out of the function is all good, but I was wandering it it’s supposed to not work or it’s a bug and should I report it (and if so, to whom is it your fault or Jackson’s).
    d
    • 2
    • 14
  • r

    Razvan

    10/12/2020, 3:54 PM
    Hi, I deployed a http4k app using Apache Server on Cloud Foundry but couldn't figure out why I can't access it... local curl (on localhost) worked ok but any way to access from outside always got a 400 (with message: "Not authoritative"). So I tried locally starting a server with simply
    app.asServer(ApacheServer(8080))
    accessing from
    <http://localhost:8080>
    no problem, but trying using the loopback ip
    127.0.0.1
    or
    0.0.0.0
    didn't work.
    ➜ curl --verbose <http://127.0.0.1:8080> 
    *   Trying 127.0.0.1:8080...
    * TCP_NODELAY set
    * Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
    > GET / HTTP/1.1
    > Host: 127.0.0.1:8080
    > User-Agent: curl/7.68.0
    > Accept: */*
    > 
    * Mark bundle as not supporting multiuse
    < HTTP/1.1 400 Bad Request
    < Connection: close
    < Date: Mon, 12 Oct 2020 13:36:26 GMT
    < Server: Apache-HttpCore/5.0.2 (Java/11.0.8)
    < Content-Length: 17
    < Content-Type: text/plain; charset=ISO-8859-1
    < 
    * Closing connection 0
    Not authoritative%
    I tried specify the address to the server
    app.asServer(ApacheServer(8080, InetAddress.getByName("0.0.0.0")))
    but no luck either. Finally gave up and move to Jetty which worked as a charm, but still wanting to know if you have an explanation or a configuration that should work with Apache. Thanks.
    s
    • 2
    • 3
  • d

    dave

    10/14/2020, 7:37 PM
    @Razvan All of the code samples on the site come directly from the http4k source tree (and are hence compiled into the build to ensure they're at least syntactically correct). because each "page" is in the same package, there can be code referenced in later snippets that appeared in others
    r
    • 2
    • 1
  • r

    Razvan

    10/15/2020, 12:29 PM
    yes inside the contact builder is simple was trying to do that in basic RoutingHttpHandler
    • 1
    • 1
Powered by Linen
Title
r

Razvan

10/15/2020, 12:29 PM
yes inside the contact builder is simple was trying to do that in basic RoutingHttpHandler
If that can help others, for now I went buidling a list of routes or null and filtering the not null ones when calling the routes() function.
val appRoutes = listOf(
   if (condition1) Route1() else null,
   if (condition2) Route2() else null,  
)

routes(*appRoutes.filterNotNull().toTypedArray())
View count: 6