Skip to content

Instantly share code, notes, and snippets.

@ritou
Created September 17, 2020 11:18
Show Gist options
  • Save ritou/5e8747241f8534b720dec0cef437f4e1 to your computer and use it in GitHub Desktop.
Save ritou/5e8747241f8534b720dec0cef437f4e1 to your computer and use it in GitHub Desktop.
  1. HTTP Client module
  defmodule Your.HttpClient do
    @behaviour Scratcher.HttpClient
    def request(method, url, body, headers, http_opts) do

      # use hackney, httpoison, httpotion...

      {:ok, %{status_code: 200, body: "..."}}
    end
  end
  1. Your Application's Config
config :your_module, http_client: Your.HttpClient
  1. Your Application/Module
  defmodule YourModule do
    @http_client Application.fetch_env!(:your_module) |> Keyword.fetch!(:http_client)

    def request(method, url, body, headers, http_opts) do
      @http_client.request(method, url, body, headers, http_opts)
    end
  end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment