MarkLogic Connect
MarkLogic Connect Client API Collection
Public Member Functions | List of all members
mlclient::Response Class Reference

Encapsulates a response from a MarkLogic server REST API. More...

#include <Response.hpp>

Public Member Functions

MLCLIENT_API Response ()
 
MLCLIENT_API void setResponseCode (const ResponseCode &code)
 Sets the HTTP response code for the Response. More...
 
MLCLIENT_API ResponseType getResponseType (void) const
 Returns the ResponseType const for the response. This is XML, JSON, Binary, Text, or Unknown. More...
 
MLCLIENT_API void setResponseType (const ResponseType &type)
 Sets the type of response received (XML, JSON, Binary, etc.), set my this API internally. More...
 
MLCLIENT_API void setResponseHeaders (const mlclient::HttpHeaders &headers)
 Sets the headers received as part of the response. More...
 
MLCLIENT_API ResponseCode getResponseCode (void) const
 Returns the HTTP response code for the response. More...
 
MLCLIENT_API mlclient::HttpHeaders getResponseHeaders (void) const
 Returns the headers that were returned with the response. More...
 
MLCLIENT_API size_t read (void *buffer, const size_t &max_size, const size_t off=0)
 Reads the raw response in to a buffer. Used for Binary responses. More...
 
MLCLIENT_API const std::string & getContent () const
 For text responses (including JSON and XML), returns the response content as a string. More...
 
MLCLIENT_API void setContent (std::string *content)
 Sets the string content for this Response. More...
 
MLCLIENT_API Response (const Response &)=delete
 
MLCLIENT_API Responseoperator= (const Response &)=delete
 

Detailed Description

Encapsulates a response from a MarkLogic server REST API.

Since
8.0.0
Date
2014-06-05

Note that a response can be XML, JSON, text, or binary content. This holds the raw response

Note
This class is deliberately low level. See the CppRestJsonHelper and PugiXmlHelper classes for how to extract a DocumentContent object from a Response object.

Constructor & Destructor Documentation

MLCLIENT_API mlclient::Response::Response ( )

Constructor

Member Function Documentation

MLCLIENT_API const std::string& mlclient::Response::getContent ( ) const

For text responses (including JSON and XML), returns the response content as a string.

Returns
The UTF-8 string
MLCLIENT_API ResponseCode mlclient::Response::getResponseCode ( void  ) const

Returns the HTTP response code for the response.

Returns
The HTTP response code
MLCLIENT_API mlclient::HttpHeaders mlclient::Response::getResponseHeaders ( void  ) const

Returns the headers that were returned with the response.

Returns
The HTTP response headers
MLCLIENT_API ResponseType mlclient::Response::getResponseType ( void  ) const

Returns the ResponseType const for the response. This is XML, JSON, Binary, Text, or Unknown.

Returns
A ResponseType enum value representing the MarkLogic response type class. This can be outputted as a string using the << operator.
MLCLIENT_API size_t mlclient::Response::read ( void *  buffer,
const size_t &  max_size,
const size_t  off = 0 
)

Reads the raw response in to a buffer. Used for Binary responses.

For binary responses, reads up to max_size bytes into buffer, starting at a given offset. For example, if an image is returned, it can be saved to a file, reading 4 k chunks. The actual number of bytes read is returned.

Parameters
[in,out]bufferThe untyped buffer to copy data in to
[in]max_sizeThe maximum amount of data in bytes to read in to the buffer
[in]offThe offset in the buffer after which this function starts writing data to
Returns
The number of bytes read
MLCLIENT_API void mlclient::Response::setContent ( std::string *  content)

Sets the string content for this Response.

This should only be set by the MarkLogic C++ API itself, never by a developer using the API.

Note
This function takes ownership of the content pointer using std::move
Parameters
[in]contentA std::unique_ptr to take ownership of the std::string content of the response.
MLCLIENT_API void mlclient::Response::setResponseCode ( const ResponseCode code)

Sets the HTTP response code for the Response.

This is normally set when the response is received. It should not be set otherwise.

Parameters
[in]codeThe HTTP response code
MLCLIENT_API void mlclient::Response::setResponseHeaders ( const mlclient::HttpHeaders headers)

Sets the headers received as part of the response.

This is set when the response is received but should not be set otherwise.

Parameters
[in]headersThe HTTP response headers
MLCLIENT_API void mlclient::Response::setResponseType ( const ResponseType type)

Sets the type of response received (XML, JSON, Binary, etc.), set my this API internally.

This is normally set when the response is received. It should not be set otherwise.

Parameters
[in]typeThe type of response

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