Azure

Installation (Gradle)

dependencies {
    implementation(platform("org.http4k:http4k-bom:5.32.2.0"))
    implementation("org.http4k:http4k-azure")
}

About

This module provides a http4k compatible HttpClient so you can http4k-ise your use of the standard Azure SDKs libraries by plugging in a standard HttpHandler. This simplifies fault testing and means that you can print out the exact traffic which is going to Azure - which is brilliant for both debugging and writing Fakes. :)

Code

package guide.reference.azure

import com.azure.core.credential.AzureKeyCredential
import com.azure.search.documents.indexes.SearchIndexClientBuilder
import org.http4k.azure.AzureHttpClient
import org.http4k.client.OkHttp
import org.http4k.core.then
import org.http4k.filter.DebuggingFilters

fun main() {
    val http4kClient = DebuggingFilters.PrintRequestAndResponse().then(OkHttp())

    val searchIndexClient = SearchIndexClientBuilder()
        .endpoint("https://....")
        .credential(AzureKeyCredential("APIKEY"))
        .httpClient(AzureHttpClient(http4kClient))
        .buildClient()

    searchIndexClient.deleteIndex("myIndex")
}