0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Julila HTTPモジュール

0
Last updated at Posted at 2022-07-28

HTTPモジュールを使う(クライアント編)

HTTPモジュールはHttp(s)を扱うモジュール。
ここではクライアント分を記すが、実はサーバーも扱える。

インストール

julia> using Pkg
julia> Pkg.add("HTTP")

利用例

using HTTP
response = HTTP.request("GET", "https://qiita.com")

println(response.request)
println(response.version)
println(response.status)
println(response.headers)
println(String(response.body))

println(response)

基本構文

request()

HTTPリクエストメッセージを送信し、レスポンスメッセージを返す。

  • HTTP.request(method, url)
  • HTTP.request(method, url, headers)
  • HTTP.request(method, url, headers, body)

パラメーター

method {String}

  • GET
  • POST
  • PUT

url {String}

  • http(s)://..の文字列

headers {String}

  • HTTPヘッダリクエストヘッダ

キーワードパラメータ

HTTP.request()には、次に示すキーワードパラメータを指定できる。

proxy {String}

プロキシのURLを指定。

query {Dict}

クエリパラメータで指定可能。

params = Dict("search" => "Qiita")
res = HTTP.get(url; query = params)

require_ssl_verification {Boolean}

SSL証明書の検証要求。

retries {Int}

リトライの回数指定。

verbose {Int}

1または2に設定で、追加メッセージロギングがおこわ割れる。

get()

GETメソッドで送信して、レスポンスメッセージを返す。
HTTP.request("GET",...)と同等

  • HTTP.get(url)
  • HTTP.get(url, headers)
  • HTTP.get(url, headers, body)

post(),put()

同様にPOST,PUTメソッドもある
HTTP.request("POSTまたはPUT",...)と同等

  • HTTP.post(url)
  • HTTP.post(url, headers)
  • HTTP.post(url, headers, body)

  • HTTP.put(url)
  • HTTP.put(url, headers)
  • HTTP.put(url, headers, body)

その他 サーバーとして扱う例

詳細は触れないがこんな感じで使える。

HTTP.listen([host=Sockets.localhost[, port=8081]]; <keyword arguments>) do http
    ...
end

その他
速くて簡単なJuliaをみなさん使ってください。

参考図書

1から始めるプログラミング

Juliaプログラミングクックブック

天才プログラマー タンメイが教える Julia超入門

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?