cppDataPipeline 0.3.0
C++ Implementation of the FAIR Data Pipeline API
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
FairDataPipeline::API Class Reference

a class which handles the fetching and posting of information to the FDP data pipeline RestAPI More...

#include <fdp/registry/api.hxx>

Public Types

typedef std::shared_ptr< APIsptr
 

Public Member Functions

Json::Value get_request (const std::string &addr_path, long expected_response=200, std::string token="")
 sends the given 'packet' of information to the RestAPI More...
 
Json::Value patch (const std::string addr_path, Json::Value &post_data, const std::string &token, long expected_response=200)
 
Json::Value post (const std::string addr_path, Json::Value &post_data, const std::string &token, long expected_response=201)
 post information from a JSON value object to the RestAPI More...
 
Json::Value post_storage_root (Json::Value &post_data, const std::string &token)
 
Json::Value post_file_type (Json::Value &post_data, const std::string &token)
 
Json::Value get_by_json_query (const std::string &addr_path, Json::Value &query_data, long expected_response=200, std::string token="")
 
Json::Value get_by_id (const std::string &table, int const &id, long expected_response=200, std::string token="")
 get an object from the api by it's id More...
 
std::string get_url_root () const
 returns the root URL for the RestAPI used by the API instance More...
 
std::string json_to_query_string (Json::Value &json_value)
 Formats a json object into a string representation which can be used as a url endpoint query. More...
 
std::string escape_space (std::string &str)
 escapes space " " characters within a string with it's html character code (%20) More...
 

Static Public Member Functions

static sptr construct (const std::string &url_root)
 construct an API object using the given URL as the root More...
 
static std::string append_with_forward_slash (std::string string)
 Static function to append a given string with a "/" unless the string is empty or already ends with a "/". More...
 
static std::string remove_leading_forward_slash (std::string str)
 Remove the leading forward slash from a given string. More...
 

Detailed Description

a class which handles the fetching and posting of information to the FDP data pipeline RestAPI


Author
K. Zarebski (UKAEA) & R. Field

The API class has know specific knowledge about the RestAPI but rather provides the interface for sending/receiving data as JSON strings

Member Function Documentation

◆ append_with_forward_slash()

std::string FairDataPipeline::API::append_with_forward_slash ( std::string  string)
static

Static function to append a given string with a "/" unless the string is empty or already ends with a "/".

Parameters
stringString to be appended with "/"
Returns
std::string Appended string

◆ construct()

API::sptr FairDataPipeline::API::construct ( const std::string &  url_root)
static

construct an API object using the given URL as the root


Author
K. Zarebski (UKAEA)
Parameters
url_rootthe root of the query address, e.g. localhost:8000/api

◆ escape_space()

std::string FairDataPipeline::API::escape_space ( std::string &  str)

escapes space " " characters within a string with it's html character code (%20)

Parameters
strstring containing space characters
Returns
std::string string with space characters represented by html character code "%20"

◆ get_by_id()

Json::Value FairDataPipeline::API::get_by_id ( const std::string &  table,
int const &  id,
long  expected_response = 200,
std::string  token = "" 
)

get an object from the api by it's id

Parameters
tableApi endpoint (table)
idid of the object
expected_responseexpected responce of the request (default 200)
Returns
Json::Value

◆ get_request()

Json::Value FairDataPipeline::API::get_request ( const std::string &  addr_path,
long  expected_response = 200,
std::string  token = "" 
)

sends the given 'packet' of information to the RestAPI

Parameters
addr_paththe api endpoint a.k.a the table name e.g. "coderun"
expected_responsethe expected return HTTP code
token
Returns
Json::Value JSON object containing the information returned by the request

◆ get_url_root()

std::string FairDataPipeline::API::get_url_root ( ) const
inline

returns the root URL for the RestAPI used by the API instance


Author
K. Zarebski (UKAEA)
Returns
URL of the RestAPI query endpoint

◆ json_to_query_string()

std::string FairDataPipeline::API::json_to_query_string ( Json::Value &  json_value)

Formats a json object into a string representation which can be used as a url endpoint query.

Parameters
json_valuethe json object to be converted typically returned by the post method
Returns
std::string

◆ post()

Json::Value FairDataPipeline::API::post ( const std::string  addr_path,
Json::Value &  post_data,
const std::string &  token,
long  expected_response = 201 
)

post information from a JSON value object to the RestAPI


Author
K. Zarebski (UKAEA) & R. Field
Parameters
addr_paththe api endpoint a.k.a the table name e.g. "coderun"
post_datathe data to transmit as a Json::Value object
keyapi token
expected_responsethe expected HTTP return code, default is 201
Returns
the result of the API post as a JSON object

◆ remove_leading_forward_slash()

std::string FairDataPipeline::API::remove_leading_forward_slash ( std::string  str)
static

Remove the leading forward slash from a given string.

Parameters
str
Returns
std::string

The documentation for this class was generated from the following files: