Gazebo Fuel_tools

API Reference

7.3.1
gz/fuel_tools/RestClient.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef GZ_FUEL_TOOLS_RESTCLIENT_HH_
18 #define GZ_FUEL_TOOLS_RESTCLIENT_HH_
19 
20 #include <map>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 #include "gz/fuel_tools/Export.hh"
26 
27 #ifdef _WIN32
28 // Disable warning C4251 which is triggered by
29 // std::string
30 #pragma warning(push)
31 #pragma warning(disable: 4251)
32 // TODO(jrivero): rename the DELETE method which is a reserved word in Windows
33 #undef DELETE
34 #endif
35 
36 namespace ignition
37 {
38  namespace fuel_tools
39  {
41  struct IGNITION_FUEL_TOOLS_VISIBLE RestResponse
42  {
44  // cppcheck-suppress unusedStructMember
45  public: int statusCode = 0;
46 
48  public: std::string data = "";
49 
54  };
55 
57  enum class HttpMethod
58  {
60  GET,
61 
63  POST,
64 
66  DELETE,
67 
69  PUT,
70 
72  PATCH,
73 
75  POST_FORM,
76 
79  };
80 
82  class IGNITION_FUEL_TOOLS_VISIBLE Rest
83  {
85  public: Rest() = default;
86 
111  public: virtual RestResponse Request(const HttpMethod _method,
112  const std::string &_url,
113  const std::string &_version,
114  const std::string &_path,
115  const std::vector<std::string> &_queryStrings,
116  const std::vector<std::string> &_headers,
117  const std::string &_data,
120 
123  public: void SetUserAgent(const std::string &_agent);
124 
127  public: const std::string &UserAgent() const;
128 
130  private: std::string userAgent;
131  };
132  }
133 }
134 
135 #ifdef _MSC_VER
136 #pragma warning(pop)
137 #endif
138 
139 #endif
STL class.
STL class.
int statusCode
The returned status code. E.g.: 200.
Definition: gz/fuel_tools/RestClient.hh:45
void SetUserAgent(const std::string &_agent)
Set the user agent name.
HttpMethod
the types of HTTP methods
Definition: gz/fuel_tools/RestClient.hh:57
Rest()=default
Default constructor.
virtual RestResponse Request(const HttpMethod _method, const std::string &_url, const std::string &_version, const std::string &_path, const std::vector< std::string > &_queryStrings, const std::vector< std::string > &_headers, const std::string &_data, const std::multimap< std::string, std::string > &_form=std::multimap< std::string, std::string >()) const
Trigger a REST request.
Stores a response to a RESTful request.
Definition: gz/fuel_tools/RestClient.hh:41
@ PATCH_FORM
Patch form method.
const std::string & UserAgent() const
Get the user agent name.
std::string data
The data received.
Definition: gz/fuel_tools/RestClient.hh:48
A helper class for making REST requests.
Definition: gz/fuel_tools/RestClient.hh:82
std::map< std::string, std::string > headers
Map of headers where the key is the header type. For example, a raw header of the form "Content-Type:...
Definition: gz/fuel_tools/RestClient.hh:53
STL class.