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

    05/29/2019, 6:39 AM
    @Razi Kheir np. have a look here and just yell if you need any more help. 🙃 https://www.http4k.org/guide/modules/clients/
    😀 1
    r
    f
    • 3
    • 8
  • r

    Razi Kheir

    05/29/2019, 8:58 AM
    David is there an option for the lenses to have optional variables inside of them? or is the data class reflected entirely only? Also, I noticed that the variable names eg “val user_name: String” will have a field “user_name” of type String. What if I wanted a variable called “user::name” its not possible to call the variable by that, is there a way around that kind of thing?
    d
    • 2
    • 4
  • r

    Razi Kheir

    05/30/2019, 12:51 AM
    David I noticed that when I define a contract, I use route and bindContract Method.GET to { request -> Response}. So it seems I can only bind the POST method to a synchronous method.. But in my case I get a request, I go to another backend asynchronously and only when I get a response from the other backend then have a callback. Is there anything I can do to go around this? Sorry for bothering you so much! and really thank you for everything!
    d
    • 2
    • 6
  • n

    Nezteb

    05/31/2019, 7:14 PM
    so i’m trying to upgrade to 3.146.0 to get that new OpenAPI goodness, but i’m getting weird stack traces anytime i try to access the generated swagger:
    -.txt
    d
    • 2
    • 11
  • d

    dave

    06/06/2019, 6:56 AM
    @Razi Kheir qq - does it work with a map instead of an object ?
    👍 1
    r
    • 2
    • 5
  • v

    Volkan Nezir

    06/13/2019, 1:53 PM
    Hi - does anyone know how to set the basePath value in either OpenApi2 or OpenApi3? Without this the links in our swagger documentation are unable to be executed. We are currently using http4k v. 3.154.0. thanks.
    d
    • 2
    • 7
  • d

    dave

    06/25/2019, 4:48 AM
    And you still also have to do things like bind the drive mapping in the docker file, and agree on a standard place to read the properties from. ... It's probably more trouble than its worth to do it with the props file tbh
    r
    • 2
    • 5
  • r

    Razi Kheir

    06/26/2019, 3:43 AM
    Hey david, letting you know of a possible bug (possibly minor): In gradle under dependencies if I have both: compile group: “org.http4k”, name: “http4k-server-netty”, version: http4kVersion and compile group: “org.http4k”, name: “http4k-server-jetty”, version: http4kVersion The generated jar file is broken, cannot find main function. I didn’t really need both, I was using only one, but took me a few hours to find out why my jar is broken since everything else was configured correctly.
    d
    • 2
    • 11
  • d

    dave

    06/27/2019, 4:54 AM
    @Razi Kheir FromResource() will load from the classpath and not from a file on disk
    👍 1
    r
    • 2
    • 9
  • r

    Razi Kheir

    07/04/2019, 2:14 AM
    Hey I was wondering why http4k Request is just an inteface that uses invokes and creates data classes instead if having an implementation of an interface too? I mean if I want to create a custom request with very few changes I still have to override everything on the interface and create them myself :X
    d
    s
    • 3
    • 7
  • v

    Volkan Nezir

    07/09/2019, 1:55 PM
    Hi - is there a way to override the body lens serialisation setting to not write empty lists as nulls?
    Nulls.AS_EMPTY
    d
    • 2
    • 8
  • p

    pabl0rg

    07/10/2019, 2:01 AM
    @Uberto Barbini one way to work around this would be to start two servers and bind one of them to 127.0.0.1 and put all lf the private endpoints there
    ☝️ 1
    u
    • 2
    • 1
  • r

    Razi Kheir

    07/10/2019, 6:27 AM
    Hey for some reason using:
    val filesystem: Environment = Environment.from(File("test.yml"))
    var testString
    var testStringLens: BiDiLens<Environment, String?> = EnvironmentKey.string().optional("TESTKEY")
    testString = environment[testStringLens]
    Only returns the string up to the first comma. Example: (yml) TESTKEY: “test1 , test2” Example: (properties) TESTKEY= “test1, test2" Will only return test1 as the string. How do I solve this? do I need to escape the string somehow? I’m trying to actually read a json from a file under a key.
    s
    d
    • 3
    • 8
  • r

    RajanS

    07/11/2019, 1:54 PM
    Hello 👋, I am looking into the contract spec and I was wondering if there is a way to specify the min/max length of a string parameter field using the contracts? https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#items-object-examples
    d
    • 2
    • 4
  • d

    dave

    07/12/2019, 9:02 PM
    For those of you into this kind of thing, Round 18 of the techempower benchmarks is out. No big surprises - http4k still consistently performing well: https://www.techempower.com/benchmarks/#section=data-r18
    🎉 3
    👍 4
    👏 1
    u
    d
    d
    • 4
    • 11
  • r

    Razi Kheir

    07/17/2019, 1:52 AM
    Hey, again 🙂 I was wondering, does http4k support HTTP/2 by default?
    s
    d
    • 3
    • 3
  • r

    Razi Kheir

    07/17/2019, 4:03 AM
    Another question, in Http4k, it seems the Health object defines two default routes “/liveness” and “/readiness” while for example in kubernetes and some other places “/liveness” is actually referred to as “healthz”, I was wondering if this is normal. I wanted to put it under /healthz, but by default I have the /liveness doing the basic liveness check instead.
    d
    • 2
    • 2
  • r

    Ricardo

    07/17/2019, 2:40 PM
    Hey I wonder if anyone is on-line to answer a quick question about the http4k contract library?
    d
    • 2
    • 26
  • r

    Ricardo

    07/18/2019, 2:32 PM
    Another quick contracts question: is there a way to include the endpoint hosting the OpenAPI JSON in the OpenApi JSON as well?
    d
    • 2
    • 2
  • d

    DALDEI

    07/23/2019, 4:00 PM
    An extrapolation of this into http4k could be a variant of the Client and Request that use an indirection of some sort instead of the explicit hostnames
    n
    d
    • 3
    • 2
  • d

    dave

    07/26/2019, 12:27 PM
    @Ricardo nope. I can just release it if you want. The only thing it hasn't got at the moment is the "include the docs route" PR.
    r
    • 2
    • 19
  • d

    dave

    07/27/2019, 8:27 AM
    @DALDEI Mainly there should be no problem, but there are a couple of things to consider: 1. You might want to plug in one of the async supporting HTTP clients instead of the blocking ones - the API here is callback based. 2. Anything that relies on threads to propagate (ZipkinTraces mainly) will also require manual transfer between Coroutine contexts. Resilience4j support will be compromised because that is also thread-based. For any of this stuff, if you could feed back any utility code for acheiving the above (even via just a Gist) that would be awesome, as these are a couple of the currently untackled items remaining on the Coroutine support work.
    d
    • 2
    • 3
  • j

    Jordan Terrell

    07/30/2019, 3:56 PM
    Any suggestions on how to enforce a maximum duration on an incoming connection? ie. I want to issue a
    Connection: close
    after a connection has been used for over 1 minute.
    s
    • 2
    • 5
  • n

    Nezteb

    07/31/2019, 5:31 PM
    Is there a way to have one endpoint
    /api
    that you can
    POST
    to and the handler switches behavior based on the ContentType of the request? I assume I’d do this with lenses, but I can’t see a way to have two different handlers. It looks like I’d have to use one.
    s
    • 2
    • 6
  • d

    DALDEI

    08/03/2019, 3:17 AM
    Having a problem understanding Body on the server side. Im using request.body.stream to feed to existing java code during a POST usually it works perfectliy but sometimes (consistantly) I get a EOF on the stream immediately. This makes sense if the stream was being read prior -- but it wasnt by me -- The comment to StreamBody is 'scary' 🙂 but I cant find a comment on how to avoid a SteamBody -- as far as I can tell debugging , the body is already a StreamBody by the time its routed to the handler -- Still a mystery why it works sometimes and not others. regardless - if I wanted to avoid the problem -- how ?? Therese some places in the source where its tested isAvailble() and conditionally uses stream or stringBody() -- can I just use stringBody() always ?
    d
    • 2
    • 12
  • d

    DALDEI

    08/03/2019, 3:28 AM
    FYI: changing to stringBody() where I was using stream 'worked' fine -- Suggest some additions to the docs in this area, its non-obvious I still dont fully understand which functions are for creating a body and which are for consuming it -- the use of invoke() makes for concise code, but difficult to know what its doing or when to use what.
    d
    • 2
    • 6
  • n

    Nezteb

    08/05/2019, 9:19 PM
    If I’m writing an HTTP4K route/handler that will return a file (CSV in this case), how would I specify that? Which page of the docs would have that info?
    d
    s
    • 3
    • 3
  • n

    Nezteb

    08/08/2019, 7:49 PM
    So, I have an HTTP4K API that was working, and then I added some new routes. As far as I can tell, they're all correctly written. They compile. but when I try to hit them, I get NPEs:
    Untitled
    • 1
    • 2
  • d

    dave

    08/08/2019, 8:11 PM
    @Nezteb glad that you’re not getting the NPE, but TBH not sure what we did to fix it!
    n
    • 2
    • 2
  • r

    Ricardo

    08/12/2019, 11:41 AM
    Opened a new PR for Google Cloud Endpoints OAuth2 support, please let me know if it is OK: https://github.com/http4k/http4k/pull/274
    d
    • 2
    • 11
Powered by Linen
Title
r

Ricardo

08/12/2019, 11:41 AM
Opened a new PR for Google Cloud Endpoints OAuth2 support, please let me know if it is OK: https://github.com/http4k/http4k/pull/274
d

dave

08/12/2019, 12:36 PM
I don't know much about this, but isn't it just a particular configuration of the existing oauth security? Is there anything to stop us reusing that stuff (with maybe some pre-canned values like we do for OAuthProvider) ?
r

Ricardo

08/12/2019, 2:10 PM
I didn't use
OAuthSecurity
because Google Cloud Endpoint delegates actual authentication to a proxy. I think
OAuthSecurity
requires a provider, but we don't.
Would you prefer that we amend
OAuthSecurity
and make the provider optional?
Also OAuth is excluded from the
SecurityRenderer
. Not sure if this was deliberate?
d

dave

08/12/2019, 2:29 PM
The OAuthSecurity definition can take a provider, but it's only through an overloaded method for convienience:
data class OAuthSecurity(
    val authorizationUrl: Uri,
    val tokenUrl: Uri,
    val scopes: List<OAuthScope> = emptyList(),
    override val filter: Filter,
    val name: String = "oauthSecurity"
) : Security {
    companion object {
        operator fun invoke(oAuthProvider: OAuthProvider,
                            customScopes: List<OAuthScope>? = null) = OAuthSecurity(
            oAuthProvider.providerConfig.authUri,
            oAuthProvider.providerConfig.tokenUri,
            customScopes ?: oAuthProvider.scopes.map { OAuthScope(it, "") },
            oAuthProvider.authFilter
        )
    }
}
We didn't add OAuth security to the OA2 renderer because we were concentrating on V3.
feel free to retrofit it.
and as an aside, is there any reason that you're not using OA3?
r

Ricardo

08/12/2019, 3:58 PM
Google Cloud Endpoints doesn't support OpenAPI3 unfortunately, and neither does the ZAP security scanner we use to pen test our API.
I'll update
OAuthSecurity
in that case with the new values as optional and add it to the
SecurityRenderer
.
Sorry to pester you, but would it possible to take a look at the udpates on this PR? It's something we need for deployment here at JL. Happy to make any changes you folks need.
View count: 5