Skip to content

dns_resolver

Manage DNS resolvers

Create

Input parameters

ParameterTypeRequiredDetails
ip_addr
IP address
String yes

Multiple addresses separated by comma

Default: null

Validation rules
RuleDetails
Present

Must be supplied and cannot be null. Must not be empty; strings must contain a non-whitespace character.

Validation error message: must be present and non-empty

label
Label
String yes

Default: null

Validation rules
RuleDetails
Present

Must be supplied and cannot be null. Must not be empty; strings must contain a non-whitespace character.

Validation error message: must be present and non-empty

is_universal
Is universal?
Boolean yes

Universal resolver is independent on location

Default: null

Validation rules
RuleDetails
Present

Must be supplied and cannot be null. Must not be empty; strings must contain a non-whitespace character.

Validation error message: must be present and non-empty

location
Location
Resource no

Location this resolver can be used on

Output parameters

ParameterTypeDescription
id
ID
Integer DNS resolver ID
ip_addr
IP address
String Multiple addresses separated by comma
label
Label
String
is_universal
Is universal?
Boolean Universal resolver is independent on location
location
Location
Resource Location this resolver can be used on

Delete

Input parameters

ParameterTypeRequiredDetails
force
Force deletion
Boolean no

Delete the DNS resolver even it is in use. Affected VPSes get a new DNS resolver.

Default: null

Output parameters

No parameters.

Index

Input parameters

ParameterTypeRequiredDetails
from_id
From ID
Integer no

List objects with IDs greater or lower than this value

Default: null

Validation rules
RuleDetails
Number
  • Must be a number after parameter type conversion.
  • Minimum: 0 (inclusive).

Validation error message: must be at least 0

limit
Limit
Integer no

Number of objects to retrieve

Default: null

Validation rules
RuleDetails
Number
  • Must be a number after parameter type conversion.
  • Minimum: 0 (inclusive).
  • Maximum: 1000 (inclusive).

Validation error message: must be between 0 and 1000

vps
VPS
Resource no

List DNS resolvers usable for a specific VPS

Output parameters

ParameterTypeDescription
id
ID
Integer DNS resolver ID
ip_addr
IP address
String Multiple addresses separated by comma
label
Label
String
is_universal
Is universal?
Boolean Universal resolver is independent on location
location
Location
Resource Location this resolver can be used on

Examples

Examples use an initialized api client, authenticated when required. See initialization and authentication.

Example #0

Ruby · Simple
reply = api.dns_resolver.index

# reply is an instance of HaveAPI::Client::ResourceInstanceList,
# which is a subclass of Array
Ruby · With error handling
begin
  require 'haveapi/client'

  api = HaveAPI::Client.new("https://api.vpsfree.cz/", version: "7.0")
  api.setup

  api.authenticate(:token, token: 'example-token')

  reply = api.dns_resolver.index

  # reply is an instance of HaveAPI::Client::ResourceInstanceList,
  # which is a subclass of Array
rescue HaveAPI::Client::ValidationError => error
  warn error.message
  warn error.errors.inspect
rescue HaveAPI::Client::ActionFailed => error
  warn error.message
  warn error.response.errors.inspect if error.response.is_a?(HaveAPI::Client::Response)
rescue HaveAPI::Client::Authentication::AuthenticationFailed, HaveAPI::Client::ProtocolError,
       RestClient::Exception, JSON::ParserError => error
  warn error.message
end
JavaScript (callback) · Simple
const resource = CallbackClient.findResource(api, ["dns_resolver"]);
const action = CallbackClient.findAction(resource, "index");
action.directInvoke({
  params: {},
  onReply: (owner, reply) => {
    if (!reply.isOk()) {
      console.error(reply.message(), reply.envelope.errors);
      return;
    }
    console.log(reply.response());
  }
});
JavaScript (callback) · With error handling
import { CallbackClient } from "haveapi-client";

const api = new CallbackClient("https://api.vpsfree.cz/", {version: "7.0"});

api.authenticate("token", {token: "example-token"}, (api, ready) => {
  if (!ready) {
    console.error("Discovery or authentication failed");
    return;
  }
  try {
    const resource = CallbackClient.findResource(api, ["dns_resolver"]);
    const action = CallbackClient.findAction(resource, "index");
    action.directInvoke({
      params: {},
      onReply: (owner, reply) => {
        if (!reply.isOk()) {
          console.error(reply.message(), reply.envelope.errors);
          return;
        }
        console.log(reply.response());
        console.log(reply.meta());
      }
    });
  } catch (error) {
    console.error(error);
  }
});
JavaScript (async) · Simple
const result = await api.resource("dns_resolver").action("index")({params: {}});
console.log(result.value);
JavaScript (async) · With error handling
import { AsyncClient, AsyncError } from "haveapi-client";

async function main() {
  const api = new AsyncClient("https://api.vpsfree.cz/", {version: "7.0"});
  try {
    await api.authenticate("token", {token: "example-token"});
    const result = await api.resource("dns_resolver").action("index")({params: {}});
    console.log(result.value);
    console.log(result.response.meta);
  } catch (error) {
    if (error instanceof AsyncError) {
      console.error(error.kind, error.message, error.errors);
    } else {
      throw error;
    }
  }
}
main().catch(error => console.error(error));
TypeScript (callback) · Simple
const resource = CallbackClient.findResource(api, ["dns_resolver"]);
const action = CallbackClient.findAction(resource, "index");
action.directInvoke({
  params: {},
  onReply: (owner, reply) => {
    if (!reply.isOk()) {
      console.error(reply.message(), reply.envelope.errors);
      return;
    }
    console.log(reply.response());
  }
});
TypeScript (callback) · With error handling
import { CallbackClient } from "haveapi-client";

const api = new CallbackClient("https://api.vpsfree.cz/", {version: "7.0"});

api.authenticate("token", {token: "example-token"}, (api, ready) => {
  if (!ready) {
    console.error("Discovery or authentication failed");
    return;
  }
  try {
    const resource = CallbackClient.findResource(api, ["dns_resolver"]);
    const action = CallbackClient.findAction(resource, "index");
    action.directInvoke({
      params: {},
      onReply: (owner, reply) => {
        if (!reply.isOk()) {
          console.error(reply.message(), reply.envelope.errors);
          return;
        }
        console.log(reply.response());
        console.log(reply.meta());
      }
    });
  } catch (error) {
    console.error(error);
  }
});
TypeScript (async) · Simple
const result = await api.resource("dns_resolver").action("index")({params: {}});
console.log(result.value);
TypeScript (async) · With error handling
import { AsyncClient, AsyncError } from "haveapi-client";

async function main(): Promise<void> {
  const api = new AsyncClient("https://api.vpsfree.cz/", {version: "7.0"});
  try {
    await api.authenticate("token", {token: "example-token"});
    const result = await api.resource("dns_resolver").action("index")({params: {}});
    console.log(result.value);
    console.log(result.response.meta);
  } catch (error) {
    if (error instanceof AsyncError) {
      console.error(error.kind, error.message, error.errors);
    } else {
      throw error;
    }
  }
}
main().catch(error => console.error(error));
Python (sync) · Simple
response = api.resources["dns_resolver"].actions["index"].call(params={})
print(response.data)
Python (sync) · With error handling
from haveapi_client import Client, ActionError, HaveAPIError, TokenAuth

try:
    with Client("https://api.vpsfree.cz/", version="7.0", auth=TokenAuth("example-token")) as api:
        response = api.resources["dns_resolver"].actions["index"].call(params={})
        print(response.data)
        print(response.meta)
except ActionError as error:
    print(error.message, error.errors)
except HaveAPIError as error:
    print(error.message, error.status_code)
Python (async) · Simple
# Run inside an async function after initializing api.
response = await api.resources["dns_resolver"].actions["index"].call(params={})
print(response.data)
Python (async) · With error handling
import asyncio

from haveapi_client import AsyncClient, ActionError, HaveAPIError, TokenAuth


async def main() -> None:
    try:
        async with AsyncClient("https://api.vpsfree.cz/", version="7.0", auth=TokenAuth("example-token")) as api:
            response = await api.resources["dns_resolver"].actions["index"].call(params={})
            print(response.data)
            print(response.meta)
    except ActionError as error:
        print(error.message, error.errors)
    except HaveAPIError as error:
        print(error.message, error.status_code)


asyncio.run(main())
Go API client · Simple
invocation := api.DnsResolver.Index.Prepare()
invocation.NewInput().SelectParameters()
response, err := invocation.Call()
if err != nil {
	fmt.Println(err)
	return
}
if !response.Status {
	fmt.Println(response.Message, response.Errors)
	return
}
for _, item := range response.Output {
	if item != nil {
		fmt.Println(item.Id)
		fmt.Println(item.IpAddr)
		fmt.Println(item.Label)
		fmt.Println(item.IsUniversal)
		fmt.Println(item.Location == nil)
	}
}
Rust API client (async) · Simple
// Use inside an async function returning Result<(), Box<dyn std::error::Error>>.
let response = api.dns_resolver().index().send().await?;
for item in &response.output {
    println!("{:?}", &item.id);
    println!("{:?}", &item.ip_addr);
    println!("{:?}", &item.label);
    println!("{:?}", &item.is_universal);
    println!("{:?}", &item.location);
}
Rust API client (async) · With error handling
// cargo add vpsadmin-client
// cargo add tokio --features macros,rt-multi-thread
// cargo add serde_json
use vpsadmin_client::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let api = match Client::builder("https://api.vpsfree.cz/")
        .basic_auth("user", "secret")
        .build() {
        Ok(api) => api,
        Err(error) => {
            eprintln!("Client configuration failed: {}", error);
            eprintln!("HTTP status: {:?}; timeout: {}", error.http_status(), error.is_timeout());
            return Err(error.into());
        }
    };
    let response = match api.dns_resolver().index().send().await {
        Ok(response) => response,
        Err(error) => {
            eprintln!("Request failed: {}", error);
            eprintln!("HTTP status: {:?}; timeout: {}", error.http_status(), error.is_timeout());
            return Err(error.into());
        }
    };
    let _ = response.http_status;
    let _ = &response.meta;
    for item in &response.output {
        println!("{:?}", &item.id);
        println!("{:?}", &item.ip_addr);
        println!("{:?}", &item.label);
        println!("{:?}", &item.is_universal);
        println!("{:?}", &item.location);
    }
    Ok(())
}
Rust API client (blocking) · Simple
// Use inside a synchronous function outside async runtime threads returning Result<(), Box<dyn std::error::Error>>.
let response = api.dns_resolver().index().send()?;
for item in &response.output {
    println!("{:?}", &item.id);
    println!("{:?}", &item.ip_addr);
    println!("{:?}", &item.label);
    println!("{:?}", &item.is_universal);
    println!("{:?}", &item.location);
}
Rust API client (blocking) · With error handling
// cargo add vpsadmin-client --features blocking
// cargo add serde_json
// Construct, use and drop this blocking client outside async runtime threads.
use vpsadmin_client::blocking::Client;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let api = match Client::builder("https://api.vpsfree.cz/")
        .basic_auth("user", "secret")
        .build() {
        Ok(api) => api,
        Err(error) => {
            eprintln!("Client configuration failed: {}", error);
            eprintln!("HTTP status: {:?}; timeout: {}", error.http_status(), error.is_timeout());
            return Err(error.into());
        }
    };
    let response = match api.dns_resolver().index().send() {
        Ok(response) => response,
        Err(error) => {
            eprintln!("Request failed: {}", error);
            eprintln!("HTTP status: {:?}; timeout: {}", error.http_status(), error.is_timeout());
            return Err(error.into());
        }
    };
    let _ = response.http_status;
    let _ = &response.meta;
    for item in &response.output {
        println!("{:?}", &item.id);
        println!("{:?}", &item.ip_addr);
        println!("{:?}", &item.label);
        println!("{:?}", &item.is_universal);
        println!("{:?}", &item.location);
    }
    Ok(())
}
TypeScript API client · Simple
// Requires an initialized api and an async context.
const result = await api.dns_resolver.index();
for (const item of result.data) {
  console.log(item.id);
  console.log(item.ip_addr);
  console.log(item.label);
  console.log(item.is_universal);
  console.log(item.location);
}
TypeScript API client · With error handling
// Configured API client: vpsadmin-typescript-client.
import { AsyncClient, AsyncError } from "haveapi-client";
import { createClient } from "vpsadmin-typescript-client";

async function main(): Promise<void> {
  try {
    const runtime = new AsyncClient("https://api.vpsfree.cz/v7.0");
    await runtime.authenticate("basic", { user: "user", password: "secret" });
    const api = createClient({ execute: spec => runtime.request(spec) });
    const result = await api.dns_resolver.index();
    void [result.data, result.meta, result.envelope, result.httpStatus];
    for (const item of result.data) {
      const value0: unknown = item.id;
      if (value0 !== null && value0 !== undefined) console.log(value0);
      const value1: unknown = item.ip_addr;
      if (value1 !== null && value1 !== undefined) console.log(value1);
      const value2: unknown = item.label;
      if (value2 !== null && value2 !== undefined) console.log(value2);
      const value3: unknown = item.is_universal;
      if (value3 !== null && value3 !== undefined) console.log(value3);
      const value4: unknown = item.location;
      if (value4 !== null && value4 !== undefined) console.log(value4);
    }
  } catch (error) {
    if (!(error instanceof AsyncError)) throw error;
    console.error(error.kind, error.httpStatus);
    throw error;
  }
}

main().catch(error => { throw error; });
PHP · Simple
$reply = $api->dns_resolver->index();

// $reply is an instance of \HaveAPI\Client\ResourceInstanceList
PHP · With error handling
try {
    $api = new \HaveAPI\Client('https://api.vpsfree.cz/', '7.0');
    $api->setup();

    $api->authenticate('token', ['token' => 'example-token']);

    $reply = $api->dns_resolver->index();

    // $reply is an instance of \HaveAPI\Client\ResourceInstanceList
} catch (\HaveAPI\Client\Exception\ValidationError $error) {
    echo $error->getMessage() . "\n";
    print_r($error->getErrors());
} catch (\HaveAPI\Client\Exception\ActionFailed $error) {
    echo $error->getMessage() . "\n";
    print_r($error->getErrors());
} catch (\HaveAPI\Client\Exception\Base $error) {
    echo $error->getMessage() . "\n";
} catch (\Exception $error) {
    // Dependency failures still propagate to the application.
    echo $error->getMessage() . "\n";
    throw $error;
}
CLI · Simple
$ haveapi-cli -u https://api.vpsfree.cz/ --version 7.0 dns_resolver index
#             ID:  26
#     IP address:  8.8.8.8
#          Label:  Google DNS
#  Is universal?:  true
#       Location:  -
# 
curl · Simple
$ curl --request GET \
       --data-binary \{\"dns_resolver\":\{\}\} \
       https://api.vpsfree.cz/v7.0/dns_resolvers

# {
#   "status": true,
#   "message": null,
#   "response": {
#     "dns_resolvers": [
#       {
#         "id": 26,
#         "ip_addr": "8.8.8.8",
#         "label": "Google DNS",
#         "is_universal": true,
#         "location": null
#       }
#     ]
#   },
#   "errors": null
# }
HTTP · Simple
GET /v7.0/dns_resolvers HTTP/1.1
Host: api.vpsfree.cz
Content-Type: application/json



HTTP/1.1 200 OK
Content-Type: application/json;charset=utf-8
Content-Length: 257

{
  "status": true,
  "message": null,
  "response": {
    "dns_resolvers": [
      {
        "id": 26,
        "ip_addr": "8.8.8.8",
        "label": "Google DNS",
        "is_universal": true,
        "location": null
      }
    ]
  },
  "errors": null
}

Show

Input parameters

No parameters.

Output parameters

ParameterTypeDescription
id
ID
Integer DNS resolver ID
ip_addr
IP address
String Multiple addresses separated by comma
label
Label
String
is_universal
Is universal?
Boolean Universal resolver is independent on location
location
Location
Resource Location this resolver can be used on

Update

Input parameters

ParameterTypeRequiredDetails
ip_addr
IP address
String no

Multiple addresses separated by comma

Default: null

label
Label
String no

Default: null

is_universal
Is universal?
Boolean no

Universal resolver is independent on location

Default: null

location
Location
Resource no

Location this resolver can be used on

Output parameters

ParameterTypeDescription
id
ID
Integer DNS resolver ID
ip_addr
IP address
String Multiple addresses separated by comma
label
Label
String
is_universal
Is universal?
Boolean Universal resolver is independent on location
location
Location
Resource Location this resolver can be used on