anfly0
exBankID - A simple abstraction over the swedish BankID api
I just released a super simple client for the Swedish BankID API.
https://hex.pm/packages/exBankID
Not all that much to say about it, just hoping it can be useful to someone!
If you like it tell a friend and put a star on the github repo
If you don’t like it all feedback is more than welcome!
Thanks!
Most Liked
krstfk
While I am not a specialist here, I have similar constraints for a project I’m working on, and I think the best path forward is to define a behaviour for the http calls and the json parsing, then it’s just a matter of implementing the callbacks for whatever library.
\Edit
You can then call functions from modules implementing the behaviour having said module declared eg in app env.
Benefits are : users can implement their own modules with libraries you didn’t think of at first and you can mock with mox.
egze
Look how ExAws does it.
Behavior: ex_aws/lib/ex_aws/request/http_client.ex at main · ex-aws/ex_aws · GitHub
This is how we implement it in our project (using Mojito instead of the default client):
defmodule DB.S3.HttpClient do
@moduledoc false
@behaviour ExAws.Request.HttpClient
def request(method, url, body, headers, http_opts \\ []) do
case Mojito.request(method, url, headers, body, http_opts) do
{:ok, response} -> {:ok, response}
{:error, error} -> {:error, %{reason: error}}
end
end
end
The implementation module is passed through config. And used in ExAws like this: ex_aws/lib/ex_aws/request.ex at main · ex-aws/ex_aws · GitHub
And I think that such a config is perfectly fine for Json and HttpClient. I don’t see any usecase where you would want to have 2 different parsers in the app, right?
egze
I’ve never built it myself in Elixir, but you can look at other libs for inspiration. Look how ex_aws does it with json GitHub - ex-aws/ex_aws: A flexible, easy to use set of clients AWS APIs for Elixir · GitHub
Maybe @benwilson512 could give some tips how to structure such a pluggable library. He mentioned some ideas in the ExAws thread. I would love a discussion about a a good architecture for a library ![]()
Popular in Announcing
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









