-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsttp.worksheet.sc
94 lines (73 loc) · 2.27 KB
/
sttp.worksheet.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import sttp.client4.quick.*
import sttp.client4.Response
import sttp.model.Uri
// val response: Response[String] = quickRequest
// .get(uri"https://httpbin.org/get")
// .send()
// response.code
// response.body
// val request = quickRequest
// .get(uri"https://example.com")
// .header("Origin", "https://scala-lang.org")
// request.headers
// val request2 = quickRequest
// .get(uri"https://example.com")
// .auth
// .basic(user = "user", password = "***")
// val book = "programming in scala"
// val bookUri: Uri = uri"https://example.com/books/$book"
// bookUri
// val queryParams = Map(
// "q" -> "scala",
// "limit" -> "10",
// "page" -> "1"
// )
// val uriWithQueryParams = uri"https://example.com/search?$queryParams"
// uriWithQueryParams
// def getUri(limit: Option[Int]): Uri = uri"https://example.com/all?limit=$limit"
// getUri(Some(10))
// getUri(None)
// def getUri2(versions: Seq[String]): Uri =
// uri"https://example.com/scala?version=$versions"
// getUri2(Seq("3.2.2"))
// getUri2(Seq("2.13.8", "2.13.9", "2.13.10"))
// getUri2(Seq.empty)
// val response2 = quickRequest
// .post(uri"https://example.com/")
// .body("Lorem ipsum")
// .send()
// response2.code
// val bytes: Array[Byte] = "john".getBytes
// val request3 = quickRequest.post(uri"https://example.com/").body(bytes)
// val json = ujson.Obj(
// "location" -> "hometown",
// "bio" -> "Scala programmer"
// )
// val response3 = quickRequest
// .patch(uri"https://api.github.com/user")
// .auth
// .bearer(sys.env("GITHUB_TOKEN"))
// .header("Content-Type", "application/json")
// .body(ujson.write(json))
// .send()
// response3.code
// response3.body
// val response3 = quickRequest
// .get(uri"https://api.github.com/user")
// .auth
// .bearer(sys.env("GITHUB_TOKEN"))
// .send()
// val json2 = ujson.read(response3.body)
// json2("login").str
// val file: java.nio.file.Path = (os.pwd / "image.png").toNIO
// val response4 = quickRequest.post(uri"https://example.com/").body(file).send()
// response4.code
val file1 = (os.pwd / "avatar1.png").toNIO
val file2 = (os.pwd / "avatar2.png").toNIO
val response5 = quickRequest
.post(uri"https://example.com/")
.multipartBody(
multipartFile("avatar1.png", file1),
multipartFile("avatar2.png", file2)
)
.send()