# SPARQL client configuration

SPARQL.Client uses Tesla (opens new window), 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 (opens new window) or ibrowse (opens new window), gun (opens new window) and mint (opens new window) are supported.

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.3"},
    {:hackney, "~> 1.6"}
  ]
end

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

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

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]])

DANGER

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

The SPARQL.Client package also supports configuring the defaults for many of the various options of the query and update functions through the application environment. See the API documentation (opens new window) for information on this.