elect
05/09/2021, 8:22 AMcurl -X GET -H "Authorization: token $token <https://api.github.com/repos/kotlin-graphics/mary/contents/$path>
I also need to parse the responding json to extract, for example, a sha encoding and create some other json to pass to some other curl
commands. Can http4k be all I need? 😛dave
05/09/2021, 8:41 AMelect
05/09/2021, 8:41 AMdave
05/09/2021, 8:43 AMelect
05/09/2021, 8:57 AMelect@5800x:~/IdeaProjects$ curl -X GET <https://api.github.com/repos/kotlin-graphics/mary/contents/mattei.txt>
{
"name": "mattei.txt",
"path": "mattei.txt",
"sha": "3f2036880b9e1cea10c06df7dccdb47179e82fcc",
"size": 5,
"url": "<https://api.github.com/repos/kotlin-graphics/mary/contents/mattei.txt?ref=master>",
"html_url": "<https://github.com/kotlin-graphics/mary/blob/master/mattei.txt>",
"git_url": "<https://api.github.com/repos/kotlin-graphics/mary/git/blobs/3f2036880b9e1cea10c06df7dccdb47179e82fcc>",
"download_url": "<https://raw.githubusercontent.com/kotlin-graphics/mary/master/mattei.txt>",
"type": "file",
"content": "cHJvdmE=\n",
"encoding": "base64",
"_links": {
"self": "<https://api.github.com/repos/kotlin-graphics/mary/contents/mattei.txt?ref=master>",
"git": "<https://api.github.com/repos/kotlin-graphics/mary/git/blobs/3f2036880b9e1cea10c06df7dccdb47179e82fcc>",
"html": "<https://github.com/kotlin-graphics/mary/blob/master/mattei.txt>"
}
}
dave
05/09/2021, 8:59 AMresponse.bodyString()
, but if you want actual JSON parsing/deserialisation, then you'll have to bring in a JSON module. Are you looking for a String, a JsonNode, or a deserialised object?elect
05/09/2021, 9:00 AM"sha"
valueelect
05/09/2021, 9:01 AMbodyString
returns an empty stringdave
05/09/2021, 9:01 AMdave
05/09/2021, 9:02 AMelect
05/09/2021, 9:02 AMfun Project.http4k() {
val token = project.property("githubToken")
val request = Request(GET, "<https://api.github.com/repos/kotlin-graphics/mary/contents/mattei.txt>")
.header("Authorization", "token $token")
println(request.bodyString())
println(request.toCurl())
}
elect
05/09/2021, 9:02 AMprintln
is empty, second
curl -X GET -H "Authorization:token .." "https://api.github.com/repos/kotlin-graphics/mary/contents/mattei.txt"
dave
05/09/2021, 9:02 AMdave
05/09/2021, 9:03 AMJavaHttpClient()(request)
elect
05/09/2021, 9:06 AMe: /home/elect/IdeaProjects/magik/plugin/src/main/kotlin/magik/MagikPlugin.kt: (172, 5): Cannot access class 'java.net.http.HttpClient'. Check your module classpath for missing or conflicting dependenciesI'm using http4k on a gradle plugin imported via composite build, importing as README
implementation(platform("org.http4k:http4k-bom:4.8.0.0"))
implementation("org.http4k:http4k-core")
implementation("org.http4k:http4k-server-netty")
implementation("org.http4k:http4k-client-apache")
dave
05/09/2021, 9:08 AMJava8HttpClient
insteadelect
05/09/2021, 9:08 AMJavaHttpClient
instead? Java 6?dave
05/09/2021, 9:08 AMdave
05/09/2021, 9:09 AMelect
05/09/2021, 9:09 AMelect
05/09/2021, 9:10 AMJava8HttpClient
seems to not generate any errors, but the ::bodyString
still empty, am I missing something else?
val request = Request(GET, "<https://api.github.com/repos/kotlin-graphics/mary/contents/mattei.txt>")
.header("Authorization", "token $token")
Java8HttpClient()(request)
println(request.bodyString())
println(request.toCurl())
dave
05/09/2021, 9:11 AMprintln(request.bodyString())
prints out the body of the request and not the responsedave
05/09/2021, 9:11 AMval response = Java8HttpClient()(request)
println(response.bodyString())
elect
05/09/2021, 9:11 AMelect
05/09/2021, 9:11 AMelect
05/09/2021, 9:14 AMresponse.close()
?dave
05/09/2021, 9:16 AMresponse.use {}
elect
05/09/2021, 9:18 AMelect
05/09/2021, 9:26 AM-d "{\"path\": \"mattei.txt\", \"message\": \"TEST-9876 add metadatafile\", \"content\": \"cHJvdmE=\", \"branch\": \"master\", \"sha\": \"3f2036880b9e1cea10c06df7dccdb47179e82fcc\"}"
elect
05/09/2021, 9:27 AMdave
05/09/2021, 9:27 AMdave
05/09/2021, 9:27 AMrequest.body("""{"path": "mattei.txt", "message": "TEST-9876 add metadatafile", "content": "cHJvdmE=", "branch": "master", "sha": "3f2036880b9e1cea10c06df7dccdb47179e82fcc"}""")
elect
05/09/2021, 9:33 AM