dependency 디펜던시 설정
build.sbt
libraryDependencies += "org.scalaj" %% "scalaj-http" % "2.4.2"
maven
<dependency>
<groupId>org.scalaj</groupId>
<artifactId>scalaj-http_${scala.version}</artifactId>
<version>2.4.2</version>
</dependency>
zeppelin
org.scalaj:scalaj-http:2.4.2
request
GET요청
e.g, http://foo.com?search=scala으로 호출 할 경우
import scalaj.http._
val response: HttpResponse[String] = Http("http://foo.com").param("search", "scala").asString
response.body
response.code
response.headers
response.cookies
Immutable Request
Http(url)은 Http.apply와 같고 HttpRequest를 immutable 로 반환한다
HttpRequest를 만들어서 재활용 가능하다
val request: HttpRequest = Http("http://date.jsontest.com/")
val responseOne = request.asString
val responseTwo = request.asString
POST요청
Http("http://foo.com/add").postForm(Seq("name" -> "jon", "age" -> "29")).asString
도움 출처 : https://index.scala-lang.org/scalaj/scalaj-http/scalaj-http/2.4.2?target=_2.13
반응형