Octane API Client
Loading...
Searching...
No Matches
Public Member Functions | List of all members
octane::internal::Fetch Class Reference

HttpClientクラスを通じてHTTP通信を行う。 More...

#include <fetch.h>

Inheritance diagram for octane::internal::Fetch:
Inheritance graph
[legend]
Collaboration diagram for octane::internal::Fetch:
Collaboration graph
[legend]

Public Member Functions

 Fetch (std::string_view token, std::string_view origin, std::string_view baseUrl, HttpClientBase *client)
 Construct a new Fetch object. More...
 
virtual ~Fetch () noexcept
 
virtual Result< _, ErrorResponseinit () override
 
virtual FetchResult request (HttpMethod method, std::string_view url) override
 
virtual FetchResult request (HttpMethod method, std::string_view url, const rapidjson::Document &body) override
 
virtual FetchResult request (HttpMethod method, std::string_view url, std::string_view mimeType, const std::vector< std::uint8_t > &body) override
 
- Public Member Functions inherited from octane::internal::FetchBase
virtual ~FetchBase () noexcept=0
 
virtual Result< _, ErrorResponseinit ()=0
 Fetchのインスタンスを初期化する。 More...
 
virtual FetchResult request (HttpMethod method, std::string_view url)=0
 APIへのボディ部を持たないリクエストを発行する。 More...
 
virtual FetchResult request (HttpMethod method, std::string_view url, const rapidjson::Document &body)=0
 APIへのJSON形式のボディ部を持つリクエストを発行する。 More...
 
virtual FetchResult request (HttpMethod method, std::string_view url, std::string_view mimeType, const std::vector< std::uint8_t > &body)=0
 APIへの任意のContent-Typeのボディ部を持つリクエストを発行する。 More...
 

Additional Inherited Members

- Public Types inherited from octane::internal::FetchBase
using FetchResult = Result< FetchResponse, ErrorResponse >
 

Detailed Description

HttpClientクラスを通じてHTTP通信を行う。

このクラスは3xx番台のレスポンスを受けたときにリダイレクト処理を行う。 また、このリダイレクト処理はHTTPヘッダのLocationに従う。

Constructor & Destructor Documentation

◆ Fetch()

octane::internal::Fetch::Fetch ( std::string_view  token,
std::string_view  origin,
std::string_view  baseUrl,
HttpClientBase client 
)

Construct a new Fetch object.

tokenは正当なAPIトークンでなければならない。 また、このトークンはHTTP拡張ヘッダ"X-Octane-API-Token"で送信される。 originはAPIサーバへのプロトコル、ドメイン、ポート番号を含む正当なAPIサーバのオリジンでなければならない。 例えば"http://localhost:3000"などの形式となる。 baseUrlはAPIと通信するときにオリジンの後につく共通のURLを指定する。 例えば"/api/v1"など。 これはFetch::requestのurl引数のベースURLとなる。 clientはHTTP通信を仲介するHttpClientBaseを実装する任意のインスタンスを指定する。通常はHttpClientクラスのインスタンスを指定すればよい。

Parameters
[in]tokenAPIに送信するトークン
[in]originAPIサーバのオリジン
[in]baseUrlAPIの起点となるURL
[in]client通信を媒介するHttpClient

◆ ~Fetch()

octane::internal::Fetch::~Fetch ( )
virtualnoexcept

Member Function Documentation

◆ init()

Result< _, ErrorResponse > octane::internal::Fetch::init ( )
overridevirtual

Fetchのインスタンスを初期化する。このメソッドはインスタンス一つにつき一度だけ呼び出すことができる。 また、インスタンスを作成した直後に呼び出さなければならない。 失敗した場合は次のエラーレスポンスを返す。

  • ERR_CURL_INITIALIZATION_FAILED: CURLの初期化に失敗したとき
Returns
Result<_, ErrorResponse> 成功した場合は何も返さず、失敗した場合は上記のエラーレスポンスを返す。

Implements octane::internal::FetchBase.

Here is the call graph for this function:

◆ request() [1/3]

Fetch::FetchResult octane::internal::Fetch::request ( HttpMethod  method,
std::string_view  url 
)
overridevirtual

APIへのボディ部を持たないリクエストを発行する。このメソッドはボディを持たないリクエストに使用する。 GET及びDELETEリクエストは必ずこのメソッドを使用しなければならない。 失敗した場合は次のエラーレスポンスを返す。

  • ERR_JSON_PARSE_FAILED: レスポンスのContent-Typeがapplication/jsonであったにもかかわらず正常なJSONデータがAPIから返却されなかったとき
  • ERR_INCORRECT_HTTP_METHOD: GET, POST, PUT, DELETE以外のHTTPメソッドを指定したとき
  • ERR_CURL_CONNECTION_FAILED: CURLの接続に失敗したとき
Parameters
[in]methodリクエストに使用するHTTPメソッド
[in]urlAPIへのURL
Returns
FetchResult 成功した場合はレスポンスのボディ部、失敗した場合は上記のエラーレスポンスを返す。

Implements octane::internal::FetchBase.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ request() [2/3]

Fetch::FetchResult octane::internal::Fetch::request ( HttpMethod  method,
std::string_view  url,
const rapidjson::Document &  body 
)
overridevirtual

APIへのJSON形式のボディ部を持つリクエストを発行する。このメソッドはJSON形式のボディを持つリクエストに使用する。 GET及びDELETEリクエストはこのメソッドを使用してはならず、代わりにFetch::request(HttpMethod method, std::string_view url)を使用すること。 失敗した場合は次のエラーレスポンスを返す。

  • ERR_JSON_PARSE_FAILED: レスポンスのContent-Typeがapplication/jsonであったにもかかわらず正常なJSONデータがAPIから返却されなかったとき
  • ERR_INCORRECT_HTTP_METHOD: POST, PUT以外のHTTPメソッドを指定したとき
  • ERR_CURL_CONNECTION_FAILED: CURLの接続に失敗したとき
Parameters
[in]methodリクエストに使用するHTTPメソッド
[in]urlAPIへのURL
[in]bodyAPIリクエストのボディ部
Returns
FetchResult 成功した場合はレスポンスのボディ部、失敗した場合は上記のエラーレスポンスを返す。

Implements octane::internal::FetchBase.

Here is the call graph for this function:

◆ request() [3/3]

Fetch::FetchResult octane::internal::Fetch::request ( HttpMethod  method,
std::string_view  url,
std::string_view  mimeType,
const std::vector< std::uint8_t > &  body 
)
overridevirtual

APIへの任意のContent-Typeのボディ部を持つリクエストを発行する。このメソッドは任意のContent-Typeのボディを持つリクエストに使用する。 JSON形式のリクエストの場合はFetch::request(HttpMethod method, std::string_view url, const rapidjson::Document& body)の使用を推奨する。 GET及びDELETEリクエストはこのメソッドを使用してはならず、代わりにFetch::request(HttpMethod method, std::string_view url)を使用すること。 失敗した場合は次のエラーレスポンスを返す。

  • ERR_JSON_PARSE_FAILED: レスポンスのContent-Typeがapplication/jsonであったにもかかわらず正常なJSONデータがAPIから返却されなかったとき
  • ERR_INCORRECT_HTTP_METHOD: POST, PUT以外のHTTPメソッドを指定したとき
  • ERR_CURL_CONNECTION_FAILED: CURLの接続に失敗したとき
Parameters
[in]methodリクエストに使用するHTTPメソッド
[in]urlAPIへのURL
[in]bodyAPIリクエストのボディ部
Returns
FetchResult 成功した場合はレスポンスのボディ部、失敗した場合は上記のエラーレスポンスを返す。

Implements octane::internal::FetchBase.

Here is the call graph for this function:

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