5
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?

いよいよはじまりました!
Qiita Tech Festa :tada::tada::tada:


はじめに

Elixirの電池入りHTTP Clientに、Reqというライブラリがあります。
クライアント証明書を指定したAPIコールをしたくなりました。

人力調査

ここで解答を得ました。

Thanksです。

ソースコード例

ソースコードの例を示します。

tapyrus_api_call.exs
Mix.install([{:req, "~> 0.5.0"}])

tapyrus_api_endpoint = System.get_env("TAPYRUS_API_ENDPOINT")
user_access_token = System.get_env("USER_ACCESS_TOKEN")

headers = [
  "Content-Type": "application/json",
  Authorization: "Bearer #{user_access_token}"
]

url = "#{tapyrus_api_endpoint}/api/v2/timestamps"

options = [
  connect_options: [transport_opts: [certfile: "cert.pem"], timeout: 60_000],
  headers: headers,
  receive_timeout: 60_000
]

Req.get!(url, options) |> IO.inspect()

実行方法 Run!!!

tapyrus_api_call.exsファイルと同じフォルダにcert.pemが置いてあることを確認して、迷わず、動かします。
環境変数のセットも忘れずに! TAPYRUS_API_ENDPOINTUSER_ACCESS_TOKEN

elixir tapyrus_api_call.exs

背景

順番が前後しますが、この記事を書いた背景です。
クライアント証明書を使うAPIの呼び出しを、Reqでしてみたかったのです。
Tapyrus APIElixirで使いたかったのです。

Tapyrus とは

Tapyrus は、Bitcoin をベースにしたオープンソースのブロックチェーンプラットフォームです。日本の企業 Chaintope によって開発されており、企業や自治体での実用を想定した設計が特徴です。

主な特徴

  • オープンソース: Bitcoin をフォークし、独自機能を追加
  • ハイブリッド設計: 制御されたネットワークで運用しつつ、透明性も確保
  • カスタムトークン: OP_COLOR による独自トークンの発行が可能

資料

さいごに

Elixirの電池入りHTTP ClientであるReqにクライアント証明書を設定してAPIコールすることができました。
あなたのElixirライフに潤いと輝きを提供できることを願ってこの記事を終えます。

5
0
0

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
5
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?