RestLink 2.2.0
Powerfull Rest Client for Qt
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
RestLink::Body Class Reference

Represents the body of an HTTP request. More...

#include <body.h>

Public Types

enum class  Type {
  PlainText , JsonData , RawData , IODevice ,
  HttpMultiPart , Unknown = -1
}
 Describes the type of content contained in the request body. More...
 

Public Member Functions

 Body ()
 Constructs an empty Body.
 
 Body (const char *data, int size=-1, const QByteArray &contentType=QByteArray())
 Constructs a Body from a C-style byte array.
 
 Body (const QByteArray &data, const QByteArray &contentType=QByteArray())
 Constructs a Body from a QByteArray.
 
 Body (const QString &text, const QByteArray &contentType=QByteArray())
 Constructs a Body from a QString.
 
 Body (const QJsonObject &object)
 Constructs a Body from a QJsonObject.
 
 Body (const QJsonArray &array)
 Constructs a Body from a QJsonArray.
 
 Body (const QJsonDocument &doc)
 Constructs a Body from a QJsonDocument.
 
 Body (const File &file)
 Constructs a Body from a RestLink::File.
 
 Body (QFile *file)
 Constructs a Body from a QFile pointer.
 
 Body (QIODevice *device, const QByteArray &contentType=QByteArray())
 Constructs a Body from a QIODevice.
 
 Body (QIODevice *device, qint64 size, const QByteArray &contentType=QByteArray())
 Constructs a Body from a QIODevice with a known content length.
 
 Body (QHttpMultiPart *multiPart)
 Constructs a Body from a QHttpMultiPart.
 
 Body (const Body &other)
 Copy constructor.
 
 Body (Body &&other)
 Move constructor.
 
 ~Body ()
 Destructor.
 
Bodyoperator= (const Body &other)
 Copy assignment operator.
 
Bodyoperator= (Body &&other)
 Move assignment operator.
 
bool hasPlainText () const
 
QByteArray toByteArray () const
 
QString toString () const
 
bool hasJsonObject () const
 
QJsonObject jsonObject () const
 
bool hasJsonArray () const
 
QJsonArray jsonArray () const
 
bool isDevice () const
 
QIODevice * device () const
 
bool isMultiPart () const
 
QHttpMultiPart * multiPart () const
 
QVariant object () const
 
Type objectType () const
 
QString contentType () const
 Returns the content type as a MIME string.
 
qint64 contentLength () const
 Returns the length of the content, if known.
 
HeaderList headers () const
 Returns the list of headers associated with the Body.
 

Detailed Description

Represents the body of an HTTP request.

The Body class provides an abstraction over various types of request payloads, including plain text, JSON data, binary data, and streaming via QIODevice or multipart form data. It allows convenient construction and inspection of content and its metadata such as content type and length.

Member Enumeration Documentation

◆ Type

enum class RestLink::Body::Type
strong

Describes the type of content contained in the request body.

This enum helps identify how the request body should be processed or interpreted.

Enumerator
PlainText 

Indicates that the body contains plain text data.

JsonData 

Indicates that the body contains JSON-encoded data.

RawData 

Indicates that the body contains raw binary data.

IODevice 

Indicates that the body is streamed from a QIODevice.

HttpMultiPart 

Indicates that the body is a multipart/form-data payload, typically used for file uploads.

Unknown 

Indicates an unknown or unsupported body type.

Constructor & Destructor Documentation

◆ Body() [1/14]

RestLink::Body::Body ( )

Constructs an empty Body.

◆ Body() [2/14]

RestLink::Body::Body ( const char *  data,
int  size = -1,
const QByteArray &  contentType = QByteArray() 
)

Constructs a Body from a C-style byte array.

Parameters
dataPointer to the data.
sizeNumber of bytes (or -1 for null-terminated).
contentTypeMIME type of the content.

◆ Body() [3/14]

RestLink::Body::Body ( const QByteArray &  data,
const QByteArray &  contentType = QByteArray() 
)

Constructs a Body from a QByteArray.

Parameters
dataThe content as a QByteArray.
contentTypeMIME type of the content.

◆ Body() [4/14]

RestLink::Body::Body ( const QString &  text,
const QByteArray &  contentType = QByteArray() 
)

Constructs a Body from a QString.

Parameters
textThe string content.
contentTypeMIME type of the content.

◆ Body() [5/14]

RestLink::Body::Body ( const QJsonObject &  object)

Constructs a Body from a QJsonObject.

◆ Body() [6/14]

RestLink::Body::Body ( const QJsonArray &  array)

Constructs a Body from a QJsonArray.

◆ Body() [7/14]

RestLink::Body::Body ( const QJsonDocument &  doc)

Constructs a Body from a QJsonDocument.

◆ Body() [8/14]

RestLink::Body::Body ( const File file)

Constructs a Body from a RestLink::File.

See also
File

◆ Body() [9/14]

RestLink::Body::Body ( QFile *  file)

Constructs a Body from a QFile pointer.

◆ Body() [10/14]

RestLink::Body::Body ( QIODevice *  device,
const QByteArray &  contentType = QByteArray() 
)

Constructs a Body from a QIODevice.

Parameters
deviceThe device supplying the data.
contentTypeMIME type of the content.

◆ Body() [11/14]

RestLink::Body::Body ( QIODevice *  device,
qint64  size,
const QByteArray &  contentType = QByteArray() 
)

Constructs a Body from a QIODevice with a known content length.

Parameters
deviceThe device supplying the data.
sizeLength of the content in bytes.
contentTypeMIME type of the content.

◆ Body() [12/14]

RestLink::Body::Body ( QHttpMultiPart *  multiPart)

Constructs a Body from a QHttpMultiPart.

◆ Body() [13/14]

RestLink::Body::Body ( const Body other)
default

Copy constructor.

◆ Body() [14/14]

RestLink::Body::Body ( Body &&  other)
default

Move constructor.

◆ ~Body()

RestLink::Body::~Body ( )
default

Destructor.

Member Function Documentation

◆ operator=() [1/2]

Body & RestLink::Body::operator= ( const Body other)

Copy assignment operator.

◆ operator=() [2/2]

Body & RestLink::Body::operator= ( Body &&  other)

Move assignment operator.

◆ hasPlainText()

bool RestLink::Body::hasPlainText ( ) const

◆ toByteArray()

QByteArray RestLink::Body::toByteArray ( ) const

◆ toString()

QString RestLink::Body::toString ( ) const

◆ hasJsonObject()

bool RestLink::Body::hasJsonObject ( ) const

◆ jsonObject()

QJsonObject RestLink::Body::jsonObject ( ) const

◆ hasJsonArray()

bool RestLink::Body::hasJsonArray ( ) const

◆ jsonArray()

QJsonArray RestLink::Body::jsonArray ( ) const

◆ isDevice()

bool RestLink::Body::isDevice ( ) const

◆ device()

QIODevice * RestLink::Body::device ( ) const

◆ isMultiPart()

bool RestLink::Body::isMultiPart ( ) const

◆ multiPart()

QHttpMultiPart * RestLink::Body::multiPart ( ) const

◆ object()

QVariant RestLink::Body::object ( ) const

◆ objectType()

Body::Type RestLink::Body::objectType ( ) const

◆ contentType()

QString RestLink::Body::contentType ( ) const

Returns the content type as a MIME string.

◆ contentLength()

qint64 RestLink::Body::contentLength ( ) const

Returns the length of the content, if known.

◆ headers()

HeaderList RestLink::Body::headers ( ) const

Returns the list of headers associated with the Body.

headers like Content-Type and Content-Length are added automatically.