environment
Manage environments
Create
Input parameters
| Parameter | Type | Required | Details | ||||
|---|---|---|---|---|---|---|---|
labelLabel |
String | no |
Environment label Default: |
||||
descriptionDescription |
String | no |
Environment description Default: |
||||
domainDomain |
String | no |
Environment FQDN, should be subject's root domain Default:
|
||||
can_create_vpsCan create a VPS |
Boolean | no |
Default: |
||||
can_destroy_vpsCan destroy a VPS |
Boolean | no |
Default: |
||||
vps_lifetimeDefault VPS lifetime |
Integer | no |
in seconds, 0 is unlimited Default: |
||||
max_vps_countMaximum number of VPS per user |
Integer | no |
0 is unlimited Default: |
||||
user_ip_ownershipUser owns IP addresses |
Boolean | no |
Default: |
Output parameters
| Parameter | Type | Description |
|---|---|---|
idID |
Integer | Environment ID |
labelLabel |
String | Environment label |
descriptionDescription |
String | Environment description |
domainDomain |
String | Environment FQDN, should be subject's root domain |
can_create_vpsCan create a VPS |
Boolean | |
can_destroy_vpsCan destroy a VPS |
Boolean | |
vps_lifetimeDefault VPS lifetime |
Integer | in seconds, 0 is unlimited |
max_vps_countMaximum number of VPS per user |
Integer | 0 is unlimited |
user_ip_ownershipUser owns IP addresses |
Boolean |
Examples
Examples use an initialized api client, authenticated when required. See initialization and authentication.
Example #0
Ruby · Simple
reply = api.environment.create({label: "Devel", domain: "vpsfree.cz"})
# reply is an instance of HaveAPI::Client::ResourceInstance
# reply.id = 2
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.environment.create({label: "Devel", domain: "vpsfree.cz"})
# reply is an instance of HaveAPI::Client::ResourceInstance
# reply.id = 2
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, ["environment"]);
const action = CallbackClient.findAction(resource, "create");
action.directInvoke({
params: {["label"]: "Devel", ["domain"]: "vpsfree.cz"},
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, ["environment"]);
const action = CallbackClient.findAction(resource, "create");
action.directInvoke({
params: {["label"]: "Devel", ["domain"]: "vpsfree.cz"},
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("environment").action("create")({params: {["label"]: "Devel", ["domain"]: "vpsfree.cz"}});
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("environment").action("create")({params: {["label"]: "Devel", ["domain"]: "vpsfree.cz"}});
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, ["environment"]);
const action = CallbackClient.findAction(resource, "create");
action.directInvoke({
params: {["label"]: "Devel", ["domain"]: "vpsfree.cz"},
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, ["environment"]);
const action = CallbackClient.findAction(resource, "create");
action.directInvoke({
params: {["label"]: "Devel", ["domain"]: "vpsfree.cz"},
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("environment").action("create")({params: {["label"]: "Devel", ["domain"]: "vpsfree.cz"}});
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("environment").action("create")({params: {["label"]: "Devel", ["domain"]: "vpsfree.cz"}});
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["environment"].actions["create"].call(params={"label": "Devel", "domain": "vpsfree.cz"})
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["environment"].actions["create"].call(params={"label": "Devel", "domain": "vpsfree.cz"})
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["environment"].actions["create"].call(params={"label": "Devel", "domain": "vpsfree.cz"})
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["environment"].actions["create"].call(params={"label": "Devel", "domain": "vpsfree.cz"})
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.Environment.Create.Prepare()
input := invocation.NewInput().SelectParameters()
input.SetLabel("Devel")
input.SetDomain("vpsfree.cz")
response, err := invocation.Call()
if err != nil {
fmt.Println(err)
return
}
if !response.Status {
fmt.Println(response.Message, response.Errors)
return
}
if response.Output != nil {
fmt.Println(response.Output.Id)
}
Rust API client (async) · Simple
// Use inside an async function returning Result<(), Box<dyn std::error::Error>>.
let response = api.environment().create().label("Devel".to_owned()).domain("vpsfree.cz".to_owned()).send().await?;
println!("{:?}", &response.output.id);
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.environment().create().label("Devel".to_owned()).domain("vpsfree.cz".to_owned()).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;
println!("{:?}", &response.output.id);
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.environment().create().label("Devel".to_owned()).domain("vpsfree.cz".to_owned()).send()?;
println!("{:?}", &response.output.id);
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.environment().create().label("Devel".to_owned()).domain("vpsfree.cz".to_owned()).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;
println!("{:?}", &response.output.id);
Ok(())
}
TypeScript API client · Simple
// Requires an initialized api and an async context.
const result = await api.environment.create({ "params": { "label": "Devel", "domain": "vpsfree.cz" } });
console.log(result.data.id);
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.environment.create({ "params": { "label": "Devel", "domain": "vpsfree.cz" } });
void [result.data, result.meta, result.envelope, result.httpStatus];
const item = result.data;
const value0: unknown = item.id;
if (value0 !== null && value0 !== undefined) console.log(value0);
} 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->environment->create([
'label' => 'Devel',
'domain' => 'vpsfree.cz'
]);
// $reply is an instance of \HaveAPI\Client\ResourceInstance
// $reply->id = 2
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->environment->create([
'label' => 'Devel',
'domain' => 'vpsfree.cz'
]);
// $reply is an instance of \HaveAPI\Client\ResourceInstance
// $reply->id = 2
} 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 environment create -- \
--label Devel \
--domain vpsfree.cz
# ID: 2
# Label: -
# Description: -
# Domain: -
# Can create a VPS: -
# Can destroy a VPS: -
# Default VPS lifetime: -
# Maximum number of VPS per user: -
# User owns IP addresses: -
#
curl · Simple
$ curl --request POST \
--data-binary \{\"environment\":\{\"label\":\"Devel\",\"domain\":\"vpsfree.cz\"\}\} \
https://api.vpsfree.cz/v7.0/environments
# {
# "status": true,
# "message": null,
# "response": {
# "environment": {
# "id": 2
# }
# },
# "errors": null
# }
HTTP · Simple
POST /v7.0/environments HTTP/1.1
Host: api.vpsfree.cz
Content-Type: application/json
{
"environment": {
"label": "Devel",
"domain": "vpsfree.cz"
}
}
HTTP/1.1 200 OK
Content-Type: application/json;charset=utf-8
Content-Length: 119
{
"status": true,
"message": null,
"response": {
"environment": {
"id": 2
}
},
"errors": null
}
Index
Input parameters
| Parameter | Type | Required | Details | ||||
|---|---|---|---|---|---|---|---|
from_idFrom ID |
Integer | no |
List objects with IDs greater or lower than this value Default:
|
||||
limitLimit |
Integer | no |
Number of objects to retrieve Default:
|
||||
has_hypervisorHas hypervisor |
Boolean | no |
List only environments having at least one hypervisor Default: |
||||
has_storageHas storage |
Boolean | no |
List only environments having at least one storage Default: |
Output parameters
| Parameter | Type | Description |
|---|---|---|
idID |
Integer | Environment ID |
labelLabel |
String | Environment label |
descriptionDescription |
String | Environment description |
domainDomain |
String | Environment FQDN, should be subject's root domain |
can_create_vpsCan create a VPS |
Boolean | |
can_destroy_vpsCan destroy a VPS |
Boolean | |
vps_lifetimeDefault VPS lifetime |
Integer | in seconds, 0 is unlimited |
max_vps_countMaximum number of VPS per user |
Integer | 0 is unlimited |
user_ip_ownershipUser owns IP addresses |
Boolean | |
maintenance_lockMaintenance lock |
String | |
maintenance_lock_reasonMaintenance reason |
String |
Examples
Examples use an initialized api client, authenticated when required. See initialization and authentication.
Example #0
Ruby · Simple
reply = api.environment.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.environment.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, ["environment"]);
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, ["environment"]);
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("environment").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("environment").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, ["environment"]);
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, ["environment"]);
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("environment").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("environment").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["environment"].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["environment"].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["environment"].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["environment"].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.Environment.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.Label)
fmt.Println(item.Domain)
}
}
Rust API client (async) · Simple
// Use inside an async function returning Result<(), Box<dyn std::error::Error>>.
let response = api.environment().index().send().await?;
for item in &response.output {
println!("{:?}", &item.id);
println!("{:?}", &item.label);
println!("{:?}", &item.domain);
}
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.environment().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.label);
println!("{:?}", &item.domain);
}
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.environment().index().send()?;
for item in &response.output {
println!("{:?}", &item.id);
println!("{:?}", &item.label);
println!("{:?}", &item.domain);
}
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.environment().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.label);
println!("{:?}", &item.domain);
}
Ok(())
}
TypeScript API client · Simple
// Requires an initialized api and an async context.
const result = await api.environment.index();
for (const item of result.data) {
console.log(item.id);
console.log(item.label);
console.log(item.domain);
}
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.environment.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.label;
if (value1 !== null && value1 !== undefined) console.log(value1);
const value2: unknown = item.domain;
if (value2 !== null && value2 !== undefined) console.log(value2);
}
} 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->environment->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->environment->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 environment index
# ID: 1
# Label: Production
# Description: -
# Domain: vpsfree.cz
# Can create a VPS: -
# Can destroy a VPS: -
# Default VPS lifetime: -
# Maximum number of VPS per user: -
# User owns IP addresses: -
# Maintenance lock: -
# Maintenance reason: -
#
curl · Simple
$ curl --request GET \
--data-binary \{\"environment\":\{\}\} \
https://api.vpsfree.cz/v7.0/environments
# {
# "status": true,
# "message": null,
# "response": {
# "environments": [
# {
# "id": 1,
# "label": "Production",
# "domain": "vpsfree.cz"
# }
# ]
# },
# "errors": null
# }
HTTP · Simple
GET /v7.0/environments 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: 201
{
"status": true,
"message": null,
"response": {
"environments": [
{
"id": 1,
"label": "Production",
"domain": "vpsfree.cz"
}
]
},
"errors": null
}
Set_maintenance
Input parameters
| Parameter | Type | Required | Details | ||||
|---|---|---|---|---|---|---|---|
lockLock |
Boolean | yes |
Default:
|
||||
reasonReason |
String | no |
Default: |
Output parameters
No parameters.
Show
Input parameters
No parameters.
Output parameters
| Parameter | Type | Description |
|---|---|---|
idID |
Integer | Environment ID |
labelLabel |
String | Environment label |
descriptionDescription |
String | Environment description |
domainDomain |
String | Environment FQDN, should be subject's root domain |
can_create_vpsCan create a VPS |
Boolean | |
can_destroy_vpsCan destroy a VPS |
Boolean | |
vps_lifetimeDefault VPS lifetime |
Integer | in seconds, 0 is unlimited |
max_vps_countMaximum number of VPS per user |
Integer | 0 is unlimited |
user_ip_ownershipUser owns IP addresses |
Boolean | |
maintenance_lockMaintenance lock |
String | |
maintenance_lock_reasonMaintenance reason |
String |
Examples
Examples use an initialized api client, authenticated when required. See initialization and authentication.
Example #0
Ruby · Simple
reply = api.environment.show(1)
# reply is an instance of HaveAPI::Client::ResourceInstance
# reply.id = 1
# reply.label = "Production"
# reply.domain = "vpsfree.cz"
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.environment.show(1)
# reply is an instance of HaveAPI::Client::ResourceInstance
# reply.id = 1
# reply.label = "Production"
# reply.domain = "vpsfree.cz"
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, ["environment"]);
const action = CallbackClient.findAction(resource, "show");
action.directInvoke(1, {
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, ["environment"]);
const action = CallbackClient.findAction(resource, "show");
action.directInvoke(1, {
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("environment").action("show")(1, {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("environment").action("show")(1, {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, ["environment"]);
const action = CallbackClient.findAction(resource, "show");
action.directInvoke(1, {
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, ["environment"]);
const action = CallbackClient.findAction(resource, "show");
action.directInvoke(1, {
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("environment").action("show")(1, {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("environment").action("show")(1, {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["environment"].actions["show"].call(path_params={"environment_id": 1}, 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["environment"].actions["show"].call(path_params={"environment_id": 1}, 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["environment"].actions["show"].call(path_params={"environment_id": 1}, 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["environment"].actions["show"].call(path_params={"environment_id": 1}, 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.Environment.Show.Prepare()
invocation.SetPathParamInt("environment_id", 1)
response, err := invocation.Call()
if err != nil {
fmt.Println(err)
return
}
if !response.Status {
fmt.Println(response.Message, response.Errors)
return
}
if response.Output != nil {
fmt.Println(response.Output.Id)
fmt.Println(response.Output.Label)
fmt.Println(response.Output.Domain)
}
Rust API client (async) · Simple
// Use inside an async function returning Result<(), Box<dyn std::error::Error>>.
let response = api.environment().show("1").send().await?;
println!("{:?}", &response.output.id);
println!("{:?}", &response.output.label);
println!("{:?}", &response.output.domain);
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.environment().show("1").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;
println!("{:?}", &response.output.id);
println!("{:?}", &response.output.label);
println!("{:?}", &response.output.domain);
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.environment().show("1").send()?;
println!("{:?}", &response.output.id);
println!("{:?}", &response.output.label);
println!("{:?}", &response.output.domain);
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.environment().show("1").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;
println!("{:?}", &response.output.id);
println!("{:?}", &response.output.label);
println!("{:?}", &response.output.domain);
Ok(())
}
TypeScript API client · Simple
// Requires an initialized api and an async context.
const result = await api.environment.show({ "path": { "environment_id": 1 } });
console.log(result.data.id);
console.log(result.data.label);
console.log(result.data.domain);
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.environment.show({ "path": { "environment_id": 1 } });
void [result.data, result.meta, result.envelope, result.httpStatus];
const item = result.data;
const value0: unknown = item.id;
if (value0 !== null && value0 !== undefined) console.log(value0);
const value1: unknown = item.label;
if (value1 !== null && value1 !== undefined) console.log(value1);
const value2: unknown = item.domain;
if (value2 !== null && value2 !== undefined) console.log(value2);
} 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->environment->show(1);
// $reply is an instance of \HaveAPI\Client\ResourceInstance
// $reply->id = 1
// $reply->label = "Production"
// $reply->domain = "vpsfree.cz"
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->environment->show(1);
// $reply is an instance of \HaveAPI\Client\ResourceInstance
// $reply->id = 1
// $reply->label = "Production"
// $reply->domain = "vpsfree.cz"
} 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 environment show 1
# ID: 1
# Label: Production
# Description: -
# Domain: vpsfree.cz
# Can create a VPS: -
# Can destroy a VPS: -
# Default VPS lifetime: -
# Maximum number of VPS per user: -
# User owns IP addresses: -
# Maintenance lock: -
# Maintenance reason: -
#
curl · Simple
$ curl --request GET \
--data-binary \{\"environment\":\{\}\} \
https://api.vpsfree.cz/v7.0/environments/1
# {
# "status": true,
# "message": null,
# "response": {
# "environment": {
# "id": 1,
# "label": "Production",
# "domain": "vpsfree.cz"
# }
# },
# "errors": null
# }
HTTP · Simple
GET /v7.0/environments/1 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: 178
{
"status": true,
"message": null,
"response": {
"environment": {
"id": 1,
"label": "Production",
"domain": "vpsfree.cz"
}
},
"errors": null
}
Update
Input parameters
| Parameter | Type | Required | Details | ||||
|---|---|---|---|---|---|---|---|
labelLabel |
String | no |
Environment label Default: |
||||
descriptionDescription |
String | no |
Environment description Default: |
||||
domainDomain |
String | no |
Environment FQDN, should be subject's root domain Default:
|
||||
can_create_vpsCan create a VPS |
Boolean | no |
Default: |
||||
can_destroy_vpsCan destroy a VPS |
Boolean | no |
Default: |
||||
vps_lifetimeDefault VPS lifetime |
Integer | no |
in seconds, 0 is unlimited Default: |
||||
max_vps_countMaximum number of VPS per user |
Integer | no |
0 is unlimited Default: |
||||
user_ip_ownershipUser owns IP addresses |
Boolean | no |
Default: |
Output parameters
| Parameter | Type | Description |
|---|---|---|
idID |
Integer | Environment ID |
labelLabel |
String | Environment label |
descriptionDescription |
String | Environment description |
domainDomain |
String | Environment FQDN, should be subject's root domain |
can_create_vpsCan create a VPS |
Boolean | |
can_destroy_vpsCan destroy a VPS |
Boolean | |
vps_lifetimeDefault VPS lifetime |
Integer | in seconds, 0 is unlimited |
max_vps_countMaximum number of VPS per user |
Integer | 0 is unlimited |
user_ip_ownershipUser owns IP addresses |
Boolean |
Examples
Examples use an initialized api client, authenticated when required. See initialization and authentication.
Example #0
Ruby · Simple
reply = api.environment.update(1, {label: "My new name", domain: "new.domain"})
# reply is an instance of HaveAPI::Client::ResourceInstance
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.environment.update(1, {label: "My new name", domain: "new.domain"})
# reply is an instance of HaveAPI::Client::ResourceInstance
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, ["environment"]);
const action = CallbackClient.findAction(resource, "update");
action.directInvoke(1, {
params: {["label"]: "My new name", ["domain"]: "new.domain"},
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, ["environment"]);
const action = CallbackClient.findAction(resource, "update");
action.directInvoke(1, {
params: {["label"]: "My new name", ["domain"]: "new.domain"},
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("environment").action("update")(1, {params: {["label"]: "My new name", ["domain"]: "new.domain"}});
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("environment").action("update")(1, {params: {["label"]: "My new name", ["domain"]: "new.domain"}});
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, ["environment"]);
const action = CallbackClient.findAction(resource, "update");
action.directInvoke(1, {
params: {["label"]: "My new name", ["domain"]: "new.domain"},
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, ["environment"]);
const action = CallbackClient.findAction(resource, "update");
action.directInvoke(1, {
params: {["label"]: "My new name", ["domain"]: "new.domain"},
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("environment").action("update")(1, {params: {["label"]: "My new name", ["domain"]: "new.domain"}});
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("environment").action("update")(1, {params: {["label"]: "My new name", ["domain"]: "new.domain"}});
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["environment"].actions["update"].call(path_params={"environment_id": 1}, params={"label": "My new name", "domain": "new.domain"})
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["environment"].actions["update"].call(path_params={"environment_id": 1}, params={"label": "My new name", "domain": "new.domain"})
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["environment"].actions["update"].call(path_params={"environment_id": 1}, params={"label": "My new name", "domain": "new.domain"})
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["environment"].actions["update"].call(path_params={"environment_id": 1}, params={"label": "My new name", "domain": "new.domain"})
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.Environment.Update.Prepare()
invocation.SetPathParamInt("environment_id", 1)
input := invocation.NewInput().SelectParameters()
input.SetLabel("My new name")
input.SetDomain("new.domain")
response, err := invocation.Call()
if err != nil {
fmt.Println(err)
return
}
if !response.Status {
fmt.Println(response.Message, response.Errors)
return
}
if response.Output != nil {
}
Rust API client (async) · Simple
// Use inside an async function returning Result<(), Box<dyn std::error::Error>>.
let response = api.environment().update("1").label("My new name".to_owned()).domain("new.domain".to_owned()).send().await?;
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.environment().update("1").label("My new name".to_owned()).domain("new.domain".to_owned()).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;
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.environment().update("1").label("My new name".to_owned()).domain("new.domain".to_owned()).send()?;
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.environment().update("1").label("My new name".to_owned()).domain("new.domain".to_owned()).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;
Ok(())
}
TypeScript API client · Simple
// Requires an initialized api and an async context.
const result = await api.environment.update({ "path": { "environment_id": 1 }, "params": { "label": "My new name", "domain": "new.domain" } });
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.environment.update({ "path": { "environment_id": 1 }, "params": { "label": "My new name", "domain": "new.domain" } });
void [result.data, result.meta, result.envelope, result.httpStatus];
const item = result.data;
} 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->environment->update(1, [
'label' => 'My new name',
'domain' => 'new.domain'
]);
// $reply is an instance of \HaveAPI\Client\ResourceInstance
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->environment->update(1, [
'label' => 'My new name',
'domain' => 'new.domain'
]);
// $reply is an instance of \HaveAPI\Client\ResourceInstance
} 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 environment update 1 -- \
--label My\ new\ name \
--domain new.domain
curl · Simple
$ curl --request PUT \
--data-binary \{\"environment\":\{\"label\":\"My\ new\ name\",\"domain\":\"new.domain\"\}\} \
https://api.vpsfree.cz/v7.0/environments/1
# {
# "status": true,
# "message": null,
# "response": {
# "environment": {}
# },
# "errors": null
# }
HTTP · Simple
PUT /v7.0/environments/1 HTTP/1.1
Host: api.vpsfree.cz
Content-Type: application/json
{
"environment": {
"label": "My new name",
"domain": "new.domain"
}
}
HTTP/1.1 200 OK
Content-Type: application/json;charset=utf-8
Content-Length: 100
{
"status": true,
"message": null,
"response": {
"environment": {}
},
"errors": null
}