SPARQL client configuration

SPARQL.Client uses Tesla, an abstraction over different HTTP client libraries. This allows you to use the HTTP client of your choice, as long as a Tesla adapter exists. Currently httpc, hackney or ibrowse.

Without further configuration, the built-in Erlang httpc is used. You can use it for simple tests or to keep your dependencies clean, but I recommend using one of the alternatives. I've experienced encoding related issues with httpc, which none of the other HTTP clients had.

If you want to use another client library, you'll have to add it to your list of dependencies in mix.exs and configure Tesla to use it.

So, for hackney you'll have to add hackney to mix.exs:

def deps do
  [
    {:sparql_client, "~> 0.2"},
    {:hackney, "~> 1.6"}
  ]
end

and add this line to your config.exs file (or environment specific configuration):

config :tesla, :adapter, Tesla.Adapter.Hackney

The ibrowse configuration looks similarly.

mix.exs:

def deps do
  [
    {:sparql_client, "~> 0.2"},
    {:ibrowse, "~> 4.2"}
  ]
end

config.exs:

config :tesla, :adapter, Tesla.Adapter.Ibrowse

If you want to pass custom, per-request middleware or adapter options for Tesla (see opts option of the Tesla.request/2 function) you can do this via the request_opts option of SPARQL.Client.querty/3 function. For example, the timeout option for the Hackney adapter can be set like this:

SPARQL.Client.query(query, "http://example.com/sparql",
    request_opts: [adapter: [recv_timeout: 30_000]])

Unfortunately, there's currently no general way to set the timeout, because of this open Tesla issue https://github.com/teamon/tesla/issues/255. So for now, timeouts must be set in an adapter-specific way like shown in the previous example.