Current section
Files
Jump to
Current section
Files
README.md
# giddy
DNS queries and hostname resolution for gleam's erlang and javascript targets by wrapping their native networking libraries.
[](https://hex.pm/packages/giddy)
[](https://giddy.hexdocs.pm/)
## using
```sh
gleam add giddy@0.1
```
```gleam
import gleam/javascript/promise // only needed for javascript target
import giddy
@target(javascript)
pub fn main() {
use result <- promise.map(gleam.gethostbyname_js("localhost", Some(giddy.V4)))
echo result
use result <- promise.map(resolve_js("example.com", giddy.Aaaa))
echo result
}
@target(erlang)
pub fn main() {
echo gethostbyname_erl("localhost", Some(giddy.V6))
echo resolve_erl("example.com", giddy.Aaaa)
}
```
Further documentation can be found at <https://giddy.hexdocs.pm/>.
## caveats
There are some differences between the javascript and erlang targets.
1. The javascript target uses promises from gleam_javascript. So while the `giddy.gethostbyname_erl` function returns `Result(List(LookupResponse), error.GiddyError)`, the `giddy.gethostbyname_js` function returns `Promise(Result(List(LookupResponse), error.GiddyError))`. That's why the functions have different names on the different targets, because the return types don't match.
2. They don't support the same DNS record types. You can query the available types with the `giddy.is_supported_js` and `giddy.is_supported_erl` functions.
- Supported javascript record types:
- `A`
- `AAAA`
- `ANY`
- `CAA`
- `CNAME`
- `MX`
- `NAPTR`
- `NS`
- `PTR`
- `SOA`
- `SRV`
- `TXT`
- `TLSA`
- Supported erlang record types:
- `A`
- `AAAA`
- `ANY`
- `CAA`
- `CNAME`
- `GID`
- `HINFO`
- `MB`
- `MD`
- `MG`
- `MF`
- `MINFO`
- `MX`
- `NAPTR`
- `NS`
- `NULL`
- `PTR`
- `SOA`
- `SPF`
- `SRV`
- `TXT`
- `UID`
- `UINFO`
- `UNSPEC`
- `WKS`
## Development
```sh
gleam run # Run the project
gleam test # Run the tests
```