ResponseFactory.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /***************************************************************************
  2. *
  3. * Project _____ __ ____ _ _
  4. * ( _ ) /__\ (_ _)_| |_ _| |_
  5. * )(_)( /(__)\ )( (_ _)(_ _)
  6. * (_____)(__)(__)(__) |_| |_|
  7. *
  8. *
  9. * Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. *
  23. ***************************************************************************/
  24. #ifndef oatpp_web_protocol_http_outgoing_ResponseFactory_hpp
  25. #define oatpp_web_protocol_http_outgoing_ResponseFactory_hpp
  26. #include "./Response.hpp"
  27. #include "oatpp/core/data/mapping/ObjectMapper.hpp"
  28. #include "oatpp/core/data/mapping/type/Type.hpp"
  29. namespace oatpp { namespace web { namespace protocol { namespace http { namespace outgoing {
  30. /**
  31. * Helper class to create http outgoing responses (&id:oatpp::web::protocol::http::outgoing::Response).
  32. */
  33. class ResponseFactory {
  34. public:
  35. /**
  36. * Create &id:oatpp::web::protocol::http::outgoing::Response; with &id:oatpp::web::protocol::http::outgoing::BufferBody;.
  37. * @param status - &id:oatpp::web::protocol::http::Status;.
  38. * @param text - &id:oatpp::String;.
  39. * @return - `std::shared_ptr` to &id:oatpp::web::protocol::http::outgoing::Response;.
  40. */
  41. static std::shared_ptr<Response> createResponse(const Status& status, const oatpp::String& text);
  42. /**
  43. * Create &id:oatpp::web::protocol::http::outgoing::Response; with &id:oatpp::web::protocol::http::outgoing::DtoBody;.
  44. * @param status - &id:oatpp::web::protocol::http::Status;.
  45. * @param dto - see [Data Transfer Object (DTO)](https://oatpp.io/docs/components/dto/).
  46. * @param objectMapper - &id:oatpp::data::mapping::ObjectMapper;.
  47. * @return - `std::shared_ptr` to &id:oatpp::web::protocol::http::outgoing::Response;.
  48. */
  49. static std::shared_ptr<Response> createResponse(const Status& status,
  50. const oatpp::Void& dto,
  51. const std::shared_ptr<data::mapping::ObjectMapper>& objectMapper);
  52. };
  53. }}}}}
  54. #endif /* oatpp_web_protocol_http_outgoing_ResponseFactory_hpp */