KanoopProtocolQt 1.2.3
Qt HTTP operations and MQTT client library
Loading...
Searching...
No Matches
httpput.h
1#ifndef HTTPPUT_H
2#define HTTPPUT_H
3#include <Kanoop/http/httpoperation.h>
4#include <Kanoop/serialization/iserializabletojson.h>
5
6/** @brief HTTP PUT operation executed asynchronously on a dedicated thread. */
7class LIBKANOOPPROTOCOL_EXPORT HttpPut : public HttpOperation
8{
9 Q_OBJECT
10public:
11 /** @brief Construct an HTTP PUT operation with an optional raw body.
12 * @param url The target URL.
13 * @param putBody The raw PUT body data. */
14 HttpPut(const QString& url, const QByteArray& putBody = QByteArray()) :
15 HttpOperation(url, Put),
16 _putBody(putBody) {}
17
18 /** @brief Construct an HTTP PUT operation with a JSON-serializable body.
19 * @param url The target URL.
20 * @param putBody The object to serialize to JSON for the PUT body. */
21 HttpPut(const QString& url, const ISerializableToJson& putBody) :
22 HttpOperation(url, Put),
23 _putBody(putBody.serializeToJson()), _isJson(true) {}
24
25 /** @brief Return the PUT request body data.
26 * @return The PUT body as a byte array. */
27 QByteArray putBody() const { return _putBody; }
28
29protected:
30 /** @brief Execute the HTTP PUT request. */
31 virtual void execute() override;
32
33 /** @brief Hook called before the PUT request is sent. */
34 virtual void prePutHook() {}
35
36 /** @brief Hook called after the PUT reply is received. */
37 virtual void postPutHook() {}
38
39private:
40 QByteArray _putBody;
41 bool _isJson = false;
42};
43
44
45#endif // HTTPPUT_H
Base class for HTTP operations executed asynchronously on a dedicated thread.
HTTP PUT operation executed asynchronously on a dedicated thread.
Definition httpput.h:8
virtual void execute() override
Execute the HTTP PUT request.
HttpPut(const QString &url, const QByteArray &putBody=QByteArray())
Construct an HTTP PUT operation with an optional raw body.
Definition httpput.h:14
QByteArray putBody() const
Return the PUT request body data.
Definition httpput.h:27
HttpPut(const QString &url, const ISerializableToJson &putBody)
Construct an HTTP PUT operation with a JSON-serializable body.
Definition httpput.h:21
virtual void prePutHook()
Hook called before the PUT request is sent.
Definition httpput.h:34
virtual void postPutHook()
Hook called after the PUT reply is received.
Definition httpput.h:37