annotate OrthancFramework/Sources/RestApi/RestApiOutput.h @ 5676:b744a2cf408a find-refactoring tip

shorten ParentRetrieveSpecification/ChildrenRetrieveSpecification as ParentSpecification/ChildrenSpecification
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 06 Jul 2024 15:04:28 +0200
parents f7adfb22e20e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1567
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
4 * Department, University Hospital of Liege, Belgium
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
11 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
12 * the License, or (at your option) any later version.
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
17 * Lesser General Public License for more details.
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
20 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
21 * <http://www.gnu.org/licenses/>.
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 **/
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #pragma once
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "../HttpServer/HttpOutput.h"
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "../HttpServer/HttpFileSender.h"
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
4392
3af1d763763a confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
30 #include <json/value.h>
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 namespace Orthanc
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 class RestApiOutput
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 private:
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4392
diff changeset
37 HttpOutput& output_;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4392
diff changeset
38 HttpMethod method_;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4392
diff changeset
39 bool alreadySent_;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4392
diff changeset
40 bool convertJsonToXml_;
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
211
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
42 void CheckStatus();
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
43
1567
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1519
diff changeset
44 void SignalErrorInternal(HttpStatus status,
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1519
diff changeset
45 const char* message,
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1519
diff changeset
46 size_t messageSize);
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1519
diff changeset
47
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 public:
1368
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
49 RestApiOutput(HttpOutput& output,
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
50 HttpMethod method);
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
51
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
52 ~RestApiOutput();
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
1046
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
54 void SetConvertJsonToXml(bool convert)
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
55 {
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
56 convertJsonToXml_ = convert;
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
57 }
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
58
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
59 bool IsConvertJsonToXml() const
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
60 {
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
61 return convertJsonToXml_;
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
62 }
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
63
4622
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
64 HttpOutput& GetLowLevelOutput() const
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
65 {
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
66 return output_;
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
67 }
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
68
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1518
diff changeset
69 void AnswerStream(IHttpStreamAnswer& stream);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
4672
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4622
diff changeset
71 void AnswerWithoutBuffering(IHttpStreamAnswer& stream);
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4622
diff changeset
72
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 void AnswerJson(const Json::Value& value);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 void AnswerBuffer(const std::string& buffer,
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
76 MimeType contentType);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
339
639272ef7615 answer raw buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
78 void AnswerBuffer(const void* buffer,
639272ef7615 answer raw buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
79 size_t length,
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
80 MimeType contentType);
339
639272ef7615 answer raw buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
81
4805
0a38000b086d Archive jobs response now contains a header Content-Disposition:filename='archive.zip'
Alain Mazy <am@osimis.io>
parents: 4672
diff changeset
82 void SetContentFilename(const char* filename);
0a38000b086d Archive jobs response now contains a header Content-Disposition:filename='archive.zip'
Alain Mazy <am@osimis.io>
parents: 4672
diff changeset
83
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
84 void SignalError(HttpStatus status);
216
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
85
1567
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1519
diff changeset
86 void SignalError(HttpStatus status,
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1519
diff changeset
87 const std::string& message);
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1519
diff changeset
88
215
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
89 void Redirect(const std::string& path);
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
90
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
91 void SetCookie(const std::string& name,
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
92 const std::string& value,
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
93 unsigned int maxAge = 0);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
94
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
95 void ResetCookie(const std::string& name);
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1046
diff changeset
96
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1046
diff changeset
97 void Finalize();
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 };
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }