This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is our map type | |
typealias FunctionalMap<K, V> = (K) -> V? | |
// An empty map never has the value | |
fun <K, V> emptyMap(): FunctionalMap<K, V> = { _ -> null } | |
// Match the key to the value or fallback | |
fun <K, V> FunctionalMap<K, V>.put(key: K, value: V): FunctionalMap<K, V> = { k -> | |
if (k == key) value else this(k) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AdjustableTickingClock( | |
private val startTime: Instant = EPOCH, | |
private val tick: Duration = Duration.ofSeconds(5) | |
) : Clock() { | |
private var currentTime = startTime | |
override fun getZone() = ZoneId.of("UTC") | |
override fun withZone(zone: ZoneId?) = this | |
override fun instant() = currentTime.also { currentTime += tick } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.http4k.example | |
import com.amazonaws.services.lambda.runtime.Context | |
import com.amazonaws.services.lambda.runtime.events.SQSEvent | |
import org.http4k.aws.AwsSdkClient | |
import org.http4k.client.JavaHttpClient | |
import org.http4k.core.HttpHandler | |
import org.http4k.core.Uri | |
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials | |
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider.create |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.azure.core.http.HttpClient | |
import com.azure.core.http.HttpHeader | |
import com.azure.core.http.HttpHeaders | |
import com.azure.core.http.HttpRequest | |
import com.azure.core.http.HttpResponse | |
import org.http4k.core.Body | |
import org.http4k.core.Body.Companion.EMPTY | |
import org.http4k.core.HttpHandler | |
import org.http4k.core.Method | |
import org.http4k.core.Request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.http4k.contract.PreFlightExtraction | |
import org.http4k.contract.contract | |
import org.http4k.contract.meta | |
import org.http4k.core.Body | |
import org.http4k.core.Filter | |
import org.http4k.core.Method.POST | |
import org.http4k.core.Request | |
import org.http4k.core.Response | |
import org.http4k.core.Status.Companion.BAD_REQUEST | |
import org.http4k.core.Status.Companion.OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val app1 = routes( | |
"/bob" bind GET to { Response(OK).body("you GET bob") }, | |
"/rita" bind POST to { Response(CREATED).body("you POST rita") } | |
) | |
val app2 = routes( | |
"/sue" bind DELETE to { Response(ACCEPTED).body("you DELETE sue") } | |
) | |
// we can compose the apps together into one large app here at the root, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am daviddenton on github. | |
* I am daviddenton (https://keybase.io/daviddenton) on keybase. | |
* I have a public key ASBCXxFMUhDpkU0nuStiO7UXK879HTLE5CitEDuRXB9oyQo | |
To claim this, I am signing this object: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyGreatFlags(args: Array<String>) : Bunting(args) { | |
val user by requiredFlag() | |
val password by requiredFlag() | |
val version by defaultedFlag("0.0.0") | |
} | |
// run the main with: java (...) Mainkt --user foo --password bar | |
fun main(args: Array<String>) = MyGreatFlags(args).use { | |
println(user) // foo | |
println(password) // bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.http4k.core.Body | |
import org.http4k.core.Method | |
import org.http4k.core.Request | |
import org.http4k.core.Response | |
import org.http4k.core.Status | |
import org.http4k.core.then | |
import org.http4k.filter.DebuggingFilters | |
import org.http4k.filter.ServerFilters | |
import org.http4k.format.Jackson.auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.http4k.core.HttpHandler | |
import org.http4k.core.Method | |
import org.http4k.core.Request | |
import org.http4k.core.Response | |
import org.http4k.core.Status | |
import org.http4k.core.Uri | |
import org.http4k.core.then | |
import org.http4k.events.AutoJsonEvents | |
import org.http4k.events.Event | |
import org.http4k.events.EventFilters |
NewerOlder