Questions tagged [http4k]

http4k is an HTTP toolkit written in Kotlin that enables the serving and consuming of HTTP services in a functional and consistent way.

http4k applications are just Kotlin functions which can be mounted into a running backend.

The principles of http4k are:

  • Application as a Function: Based on the Twitter paper "Your Server as a Function", all HTTP services can be composed of 2 types of simple function: HttpHandler, Filter
  • Immutability: All entities in the library are immutable unless their function explicitly disallows this.
  • Symmetric: The HttpHandler interface is identical for both HTTP services and clients. This allows for simple offline testability of applications, as well as plugging together of services without HTTP container being required.
  • Dependency-lite: Apart the from Kotlin StdLib, http4k-core module has ZERO dependencies and weighs in at ~700kb. Add-on modules only have dependencies required for specific implementation.
  • Testability Built by TDD enthusiasts, so supports super-easy mechanisms for testing.
  • Modularity: Common behaviours are abstracted into the http4k-core module, but there are several pluggable modules for different purposes.

Project website: https://www.http4k.org/

Github Project Organization: https://github.com/http4k

23 questions
7
votes
1 answer

How to understand Kotlin Functional Interface with companion object inside?

I would like to get some help to understand a Kotlin code snippet about functional interface used in Http4k org.http4k.core package typealias HttpHandler = (Request) -> Response fun interface Filter : (HttpHandler) -> HttpHandler { companion…
danny
  • 3,046
  • 3
  • 23
  • 28
4
votes
1 answer

Why responses my heroku hosted container app with "Not authoritative"

I try to run my simple Web-App as Docker Container within Heroku. When build and run the container locally all works fine. But on accessing the generated endpoint https://html5-landingpage-buddah.herokuapp.com/ Heroku responses with HTTP 400 Bad…
Oliver
  • 332
  • 1
  • 11
4
votes
4 answers

How to expose swagger UI with http4k?

I'm building a microservice with the http4k framework using their Contract APIs. I can easily expose the swagger API description JSON on eg. /swagger.json with fun app(): HttpHandler = "/" bind contract { renderer = OpenApi3(ApiInfo("GoOut…
Jen
  • 1,206
  • 9
  • 30
3
votes
2 answers

Kotlin http4k : how to get a json field from the body of a Response?

Below is shown the body of a Response of an http4k JavaHttpClient : '{"Hash":"QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH","Size":0,"CumulativeSize":6,"Blocks":0,"Type":"file"} Which Kotlin module can be used to extract the values of the…
Emile Achadde
  • 1,715
  • 3
  • 10
  • 22
3
votes
1 answer

Idiomatic way of implementing global error handler in http4k

I tried to find an answer in project's documentation but couldn't find anything useful. What is the best practice to implement a global error handler that captures all the exceptions and returns appropriate http status based on the exception type?
alisabzevari
  • 8,008
  • 6
  • 43
  • 67
2
votes
2 answers

How to verify request is coming from Twilio on Google Cloud Platform with http4k?

I have a server using Kotlin 1.5, JDK 11, http4k v4.12, and I've got the Twilio Java SDK v8.19, hosted using Google Cloud Run. I've created a predicate using Twilio's Java SDK RequestValidator. import com.twilio.security.RequestValidator import…
aSemy
  • 5,485
  • 2
  • 25
  • 51
2
votes
1 answer

Create a Docker Image for a Kotlin http4k backend with gradle as a build tool

Iam trying to build a docker image for a Kotlin http4k backend but i cant get it quite working. I can't create a fat jar so my dependencies are missing when i try to run the image. So i get a ClassNotFound exception. Here is my build.gradle…
Linde_98
  • 418
  • 4
  • 10
2
votes
2 answers

Is it possible to use http4k to stream long reponses?

I would like to use http4k to stream a long response. I plan to use Content-type: multipart/x-mixed-replace so I push data to the client quite endlessly. In http4k, we have typealias HttpHandler = (Request) -> Response. But my handler cannot return…
Pierre Thibault
  • 1,895
  • 2
  • 19
  • 22
2
votes
1 answer

How to map multiple HTTP Verbs to the same path in HTTP4K

I have a route similar to the one below working fine in HTTP4K. However it is annoying having to repeat the calls to "/" bind. I have looked for a simpler way to express the DSL but nothing else seems to work. Is there any way to achieve…
Garth Gilmour
  • 11,124
  • 5
  • 25
  • 35
2
votes
1 answer

Error with Building Fatjar Using Kotlin DSL

I am trying to build a fatjar using ShadowJar. My app and gradle code are below. I'm using Gradle 5.0 for the build. When I run ./gradlew run, the code works. When I run 'gradle shadowjar', and run the fatjar using 'java -jar' in the 'build/lib'…
Dan Largo
  • 1,075
  • 3
  • 11
  • 25
2
votes
2 answers

How to configure Jackson mapper

How can I globally configure json serializer for http4k? For example, snake case field names or formatting DateTime as ISO8601.
alisabzevari
  • 8,008
  • 6
  • 43
  • 67
1
vote
1 answer

Configuring SSL for Jetty in http4k

I am trying to make my http4k REST API require SSL but I can't manage to figure out how to configure Jetty for SSL.
Cosmin_Victor
  • 154
  • 1
  • 13
1
vote
1 answer

How to use http4k-jsonrpc from http4k project?

According http4k documentation to configure JSON-RPC server I should use JsonRpc.auto or JsonRpc.manual, but unfortunately I can't find any example. API doc contains something like: fun auto(json: JsonLibAutoMarshallingJson,…
1
vote
1 answer

How do you model a path parameter in the middle with http4k

I am using http4k-contracts and I am trying to model a route with a path parameter in the middle of the path, i.e. This is the path: /player/{id}/match This is my code (does not compile): "/player/" / Path.string().of("id") / "match" meta { .. Whats…
reikje
  • 2,850
  • 2
  • 24
  • 44
0
votes
1 answer

Delete metadata from doc, docx, pdf files which are stored as blob on GCS (Google cloud services)

Current Problem :- I have a setup of GCS to which i am uploading some files such as doc, docx, pdf. With the file upload the default metadata is also getting uploaded. THE FILES ARE GETTING UPLOADED AS A Blob. When we try to access the file I am…
1
2