Class RESTApiServerWrapper

Class Documentation

class RESTApiServerWrapper

Utility class to facilitate HTTP requests between the environments REST API and C++ drivers.

Public Functions

explicit RESTApiServerWrapper(const std::string &url = "http://0.0.0.0:8001/api", const bool initialize = true)

Constructor.

inline bool is_inisialised() const noexcept

Returns true if the server is initialised.

inline std::string get_url() const noexcept

Returns the remote url.

std::string get_env_url(const std::string &name) const noexcept

Return the url for the environment with the given name.

std::string get_uri(const std::string &name) const noexcept

Returns the URI of the environment with the given name Returns INVALID_STR if the environment is not registered.

void register_new(const std::string &name, const std::string &uri)

Register a new environment. Throws std::logic_error if the environment name already exists.

void register_if_not(const std::string &name, const std::string &uri)

Same as register_new but swallows the thrown exception.

nlohmann::json is_alive(const std::string &env_name, const uint_t cidx) const

Queries the remote server if the environment with the given cidx is alive Throws std::logic_error is the environment is not registered.

nlohmann::json close(const std::string &env_name, const uint_t cidx) const

Close the environment with the given name. Throws std::logic_error is the environment is not registered Throws std::runtime_error if the server response is not 201.

template<typename ActionType>
nlohmann::json step(const std::string &env_name, const uint_t cidx, const ActionType &action) const

Step in the environment with the given name and the given copy index executing action. ActionType has to be JSON serializable Throws std::logic_error is the environment is not registered Throws std::runtime_error if the server response is not 201.

nlohmann::json reset(const std::string &env_name, const uint_t cidx, const uint_t seed, const nlohmann::json &options) const

Reset the the environment with the given name and the given copy index executing action. Throws std::logic_error is the environment is not registered Throws std::runtime_error if the server response is not 202.

nlohmann::json make(const std::string &env_name, const uint_t cidx, const std::string &version, const nlohmann::json &options) const

Make the the environment with the given name and the given copy index executing action. Throws std::logic_error is the environment is not registered Throws std::runtime_error if the server response is not 202.

nlohmann::json dynamics(const std::string &env_name, const uint_t cidx, const uint_t sidx, const uint_t aidx) const

Get the dynamics of the environment. If the environment does not expose such an endpoint it returns 404.

inline nlohmann::json copy(const std::string &env_name, const uint_t cidx, const std::string &version, const nlohmann::json &options) const

Make the cidx copy of the environment.

bool has_gymnasium() const
std::vector<std::string> gymnasium_envs() const