# `JSV.Resolver.Httpc`
[🔗](https://github.com/lud/jsv/blob/v0.18.3/lib/jsv/resolver/httpc.ex#L1)

A `JSV.Resolver` implementation that will fetch the schemas from the web with
the help of the `:httpc` module.

This resolver requires a list of allowed URL prefixes to download from. It
also needs a proper JSON library to decode fetched schemas:

* From Elixir 1.18, the `JSON` module is automatically available in the
  standard library.
* JSV can use [Jason](https://hex.pm/packages/jason) if listed in your
  dependencies with the  `"~> 1.0"` requirement.
* JSV also supports [Poison](https://hex.pm/packages/poison) with the `"~> 6.0
  or ~> 5.0"` requirement.

Schemas known by the `JSV.Resolver.Embedded` will be fetched from that module
instead of being fetched from the web. Allowed prefixes are not needed for
those schemas.

### Options

This resolver supports the following options:

- `:allowed_prefixes` - This option is mandatory and contains the allowed
  prefixes to download from. For security reasons, the prefixes should contain
  at leath the first `/` of the URI path, like `https://example.com/` instead
  of `https://example.com`.
- `:cache_dir` - The path of a directory to cache downloaded resources. The
  default value can be retrieved with `default_cache_dir/0` and is based on
  `System.tmp_dir!/0`. The option also accepts `false` to disable that cache.
  Note that there is no cache expiration mechanism.

### Example

    iex> resolver_opts = [allowed_prefixes: ["https://www.schemastore.org/"], cache_dir: "_build/custom/dir"]
    iex> {:ok, _root} = JSV.build(%{"$ref": "https://www.schemastore.org/github-action.json"}, resolver: {JSV.Resolver.Httpc, resolver_opts})

# `default_cache_dir`

```elixir
@spec default_cache_dir() :: binary()
```

Returns the default directory used by the disk-based cache.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
