# `ExIbge.Locality.Microregion`
[🔗](https://github.com/pedrohfonseca81/ex_ibge/blob/main/lib/ex_ibge/locality/microregion.ex#L1)

Module for handling Microregion (Microrregião) queries from IBGE.

Microregions are subdivisions of mesoregions, grouping municipalities with
similar geographic and economic characteristics.

> Note: Microregions were replaced by Immediate Geographic Regions in 2017,
> but this API endpoint is still available for historical data.

# `all`

```elixir
@spec all(Keyword.t()) :: {:ok, [ExIbge.Geography.Microregion.t()]} | {:error, any()}
```

Get all microregions.

## Parameters

  * `query` - Optional parameters supported by the API (e.g., `order_by: :name`).

## Examples

    iex> ExIbge.Locality.Microregion.all()
    {:ok, [%ExIbge.Geography.Microregion{id: 11001, name: "Ji-Paraná", ...}, ...]}

## See Also

[IBGE API: Microrregiões](https://servicodados.ibge.gov.br/api/docs/localidades#api-Microrregioes-microrregioesGet)

# `all!`

```elixir
@spec all!(Keyword.t()) :: [ExIbge.Geography.Microregion.t()]
```

Same as `all/1`, but raises an error on failure.

# `find`

```elixir
@spec find(integer() | String.t() | [integer() | String.t()], Keyword.t()) ::
  {:ok, [ExIbge.Geography.Microregion.t()]} | {:error, any()}
```

Get microregion(s) by identifier(s).

## Parameters

  * `ids` - A single integer ID or a list of integer IDs.
  * `query` - Optional parameters supported by the API.

## Examples

    iex> ExIbge.Locality.Microregion.find(33007)
    {:ok, [%ExIbge.Geography.Microregion{id: 33007, name: "Nova Friburgo", ...}]}

## See Also

[IBGE API: Microrregião por ID](https://servicodados.ibge.gov.br/api/docs/localidades#api-Microrregioes-microrregioesIdGet)

# `find!`

```elixir
@spec find!(integer() | String.t() | [integer() | String.t()], Keyword.t()) :: [
  ExIbge.Geography.Microregion.t()
]
```

Same as `find/2`, but raises an error on failure.

# `get_by_mesoregion`

```elixir
@spec get_by_mesoregion(
  integer() | String.t() | [integer() | String.t()],
  Keyword.t()
) ::
  {:ok, [ExIbge.Geography.Microregion.t()]} | {:error, any()}
```

Get microregions by mesoregion identifier(s).

## Parameters

  * `mesoregion_ids` - A single integer ID or a list of integer IDs.
  * `query` - Optional parameters supported by the API.

## Examples

    iex> ExIbge.Locality.Microregion.get_by_mesoregion(3303)
    {:ok, [%ExIbge.Geography.Microregion{...}, ...]}

## See Also

[IBGE API: Microrregiões por Mesorregião](https://servicodados.ibge.gov.br/api/docs/localidades#api-Microrregioes-mesorregioesMesorregiaoMicrorregioesGet)

# `get_by_mesoregion!`

```elixir
@spec get_by_mesoregion!(
  integer() | String.t() | [integer() | String.t()],
  Keyword.t()
) :: [
  ExIbge.Geography.Microregion.t()
]
```

Same as `get_by_mesoregion/2`, but raises an error on failure.

# `get_by_region`

```elixir
@spec get_by_region(integer() | String.t() | [integer() | String.t()], Keyword.t()) ::
  {:ok, [ExIbge.Geography.Microregion.t()]} | {:error, any()}
```

Get microregions by region identifier(s).

## Parameters

  * `region_ids` - A single integer ID or a list of integer IDs (1-5).
  * `query` - Optional parameters supported by the API.

## Examples

    iex> ExIbge.Locality.Microregion.get_by_region(3)
    {:ok, [%ExIbge.Geography.Microregion{...}, ...]}

## See Also

[IBGE API: Microrregiões por Região](https://servicodados.ibge.gov.br/api/docs/localidades#api-Microrregioes-regioesRegiaoMicrorregioesGet)

# `get_by_region!`

```elixir
@spec get_by_region!(integer() | String.t() | [integer() | String.t()], Keyword.t()) ::
  [
    ExIbge.Geography.Microregion.t()
  ]
```

Same as `get_by_region/2`, but raises an error on failure.

# `get_by_state`

```elixir
@spec get_by_state(
  integer() | atom() | String.t() | [integer() | atom() | String.t()],
  Keyword.t()
) :: {:ok, [ExIbge.Geography.Microregion.t()]} | {:error, any()}
```

Get microregions by state identifier(s).

## Parameters

  * `uf_ids` - A single identifier or list of identifiers (Integer ID or Atom UFs).
  * `query` - Optional parameters supported by the API.

## Examples

    iex> ExIbge.Locality.Microregion.get_by_state(33)
    {:ok, [%ExIbge.Geography.Microregion{...}, ...]}

    iex> ExIbge.Locality.Microregion.get_by_state(:rj)
    {:ok, [%ExIbge.Geography.Microregion{...}, ...]}

## See Also

[IBGE API: Microrregiões por UF](https://servicodados.ibge.gov.br/api/docs/localidades#api-Microrregioes-estadosUFMicrorregioesGet)

# `get_by_state!`

```elixir
@spec get_by_state!(
  integer() | atom() | String.t() | [integer() | atom() | String.t()],
  Keyword.t()
) :: [ExIbge.Geography.Microregion.t()]
```

Same as `get_by_state/2`, but raises an error on failure.

---

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