Last active
October 9, 2024 18:08
-
-
Save dacr/3ac4eb919aa81190bf63bf02dfe55205 to your computer and use it in GitHub Desktop.
List a user github gists using sttp for client http and circe for json processing. / published by https://github.com/dacr/code-examples-manager #e2a1acae-e413-4b91-97d9-f720000a1209/76b768845995f749f27ab579fca20cada04cebb8
This file contains hidden or 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
// summary : List a user github gists using sttp for client http and circe for json processing. | |
// keywords : scala, sttp, circe, json, gists-api | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : e2a1acae-e413-4b91-97d9-f720000a1209 | |
// created-on : 2020-05-31T19:54:52Z | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file | |
//> using scala 2.12.20 | |
//> using dep com.softwaremill.sttp::core:1.5.17 | |
//> using dep com.softwaremill.sttp::circe:1.5.17 | |
//> using dep io.circe::circe-generic:0.11.1 // Keep in sync with sttp.circe used circe release | |
import com.softwaremill.sttp.quick._ | |
import com.softwaremill.sttp.circe._ | |
import io.circe.generic.auto._ | |
case class Gist( | |
id:String, | |
description:String, | |
html_url:String, | |
public:Boolean, | |
) | |
val user = "dacr" | |
val query = uri"https://api.github.com/users/$user/gists?page=1&per_page=10" | |
val response =sttp.get(query).response(asJson[Array[Gist]]).send() | |
val next = response.header("Link") // it provides the link for the next & last page :) | |
val gists = response.body.right.get.right.get | |
println("10 last gists :") | |
gists.foreach{ println } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment