Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cloudnode-pro/hetzner-dns-client
Hetzner DNS API client for Node.js
https://github.com/cloudnode-pro/hetzner-dns-client
client hetzner hetzner-api hetzner-dns
Last synced: about 1 month ago
JSON representation
Hetzner DNS API client for Node.js
- Host: GitHub
- URL: https://github.com/cloudnode-pro/hetzner-dns-client
- Owner: cloudnode-pro
- License: gpl-3.0
- Created: 2023-01-13T13:56:36.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-01T18:07:41.000Z (6 months ago)
- Last Synced: 2024-10-13T06:56:32.839Z (3 months ago)
- Topics: client, hetzner, hetzner-api, hetzner-dns
- Language: TypeScript
- Homepage:
- Size: 188 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Node.js Hetzner DNS API Client
[![Hetzner DNS API Version](https://shields.io/badge/v1-%23D50C2D?label=Hetnzner%20DNS%20API&logo=hetzner&labelColor=%2324292E)](https://dns.hetzner.com/api-docs/)
[![Version](https://img.shields.io/npm/v/hetzner-dns-client.svg)](https://npmjs.org/package/hetzner-dns-client)
[![Downloads](https://img.shields.io/npm/dt/hetzner-dns-client.svg)](https://npmjs.org/package/hetzner-dns-client)Hetzner DNS API client for Node.js
## Installation
```bash
npm i hetzner-dns-client
```## Usage
You can use this client library with your Node.js project.### JavaScript Example
```js
import {HetznerDnsClient, DnsRecord} from 'hetzner-dns-client';// create client instance
const client = new HetznerDnsClient("YOUR_API_TOKEN");
// get zone by ID
const zone = await client.zones.get("ZONE_ID");
// create apex/root zone record of type "A" to 127.0.0.1
const record = await zone.createRecord("@", DnsRecord.Type.A, "127.0.0.1");
```### TypeScript Example
```ts
import {HetznerDnsClient, DnsRecord, Zone} from 'hetzner-dns-client';// create client instance
const client: HetznerDnsClient = new HetznerDnsClient("YOUR_API_TOKEN");
// get zone by ID
const zone: Zone = await client.zones.get("ZONE_ID");
// create apex/root zone record of type "A" to 127.0.0.1
const record: DnsRecord = await zone.createRecord("@", DnsRecord.Type.A, "127.0.0.1");
```### Handling Errors
Methods that may throw an error are marked with `throws` in the documentation and specify what error types may be thrown. You can catch these errors with a `try/catch` block.For example:
```js
try {
const zone = await client.zones.get("ID that does not exist");
}
catch (err) {
if (err instanceof ApiError)
console.error(err); // the Hetzner API returned an error, e.g. "Zone not found"
else if (err instanceof ClientParseError)
console.error(err); // the client could not understand or parse the response from the Hetzner API
else
console.error(err); // some other error occurred
}
```## API Documentation
The official Hetzner DNS API documentation can be found on [https://dns.hetzner.com/api-docs/](https://dns.hetzner.com/api-docs/).> **Note**: The Hetzner DNS API documentation appears to be incomplete and contains a few errors. The documentation of this client library is a separate documentation and some functionality may be described differently.
>
> If you find any errors in the documentation, or think that further clarification is needed, please open an issue or pull request.The client library documentation is available in DOCS.md in this repository.