A simple example of using the Unkey Elixir SDK.
A simple example of using the Unkey Elixir SDK.
The package can be installed from Hex PM by adding
Note: This project uses Elixir version
1.13.
def deps do [ {:unkey_elixir_sdk, "~> 0.1.1"} ] end
This example uses a supervision tree to start the SDK
The GenServer takes a map with two properties.
children = [ {UnkeyElixirSdk, %{token: "yourunkeyapitoken"}} ] # Now we start the supervisor with the children and a strategy {:ok, pid} = Supervisor.start_link(children, strategy: :one_for_one) # After started, we can query the supervisor for information Supervisor.count_children(pid) #=> %{active: 1, specs: 1, supervisors: 0, workers: 1}
NOTE In order to run this project either create a
config/dev.secret.exsfile with the keyunkey_elixir_sdk_exampleand values specified in.env.example(token & apiId) OR directly use the environment variables in code (not recommended).
You can run the project via the IEX console.
iex -S mix
and call the methods like so:
ElixirMixSupervisionExample.create_key_via_sdk
The full list of callable methods can be found here.