controller.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. Copyright 2017 Herik Lima de Castro and Marcelo Medeiros Eler
  3. Distributed under MIT license, or public domain if desired and
  4. recognized in your jurisdiction.
  5. See file LICENSE for detail.
  6. */
  7. #ifndef CONTROLLER_H
  8. #define CONTROLLER_H
  9. #include <QString>
  10. #include "cppwebframework_global.h"
  11. CWF_BEGIN_NAMESPACE
  12. class Request;
  13. class Response;
  14. /**
  15. * @brief The Controller class is responsable to attend a request from a specific url.
  16. * You will need to create a derived class from Controller and then, reconstruct the
  17. * desired method to response a request, after this, you will need mapping the url to the
  18. * new controller that you created, you need to do it into the ConfigureCppWebServer using
  19. * the method addUrlController.
  20. */
  21. class CPPWEBFRAMEWORKSHARED_EXPORT Controller
  22. {
  23. /**
  24. * @brief This method is used to make a default response.
  25. * @param req : This is a reference to the Request.
  26. * @param resp : This is a reference to the Response.
  27. * @param method : This parameter holds the method name.
  28. */
  29. void doMessage(Request &req, Response &resp, const QString &method) const;
  30. public:
  31. /**
  32. * @brief Destructor.
  33. */
  34. virtual ~Controller() = default;
  35. /**
  36. * @brief This is an virtual method that can be overloaded to attend the delete request method.
  37. * @param req : This is a reference to the Request.
  38. * @param resp : This is a reference to the Response.
  39. */
  40. virtual void doDelete(Request &req, Response &resp) const;
  41. /**
  42. * @brief This is an virtual method that can be overloaded to attend the get request method.
  43. * @param req : This is a reference to the Request.
  44. * @param resp : This is a reference to the Response.
  45. */
  46. virtual void doGet(Request &req, Response &resp) const;
  47. /**
  48. * @brief This is an virtual method that can be overloaded to attend the options request method.
  49. * @param req : This is a reference to the Request.
  50. * @param resp : This is a reference to the Response.
  51. */
  52. virtual void doOptions(Request &req, Response &resp) const;
  53. /**
  54. * @brief This is an virtual method that can be overloaded to attend the post request method.
  55. * @param req : This is a reference to the Request.
  56. * @param resp : This is a reference to the Response.
  57. */
  58. virtual void doPost(Request &req, Response &resp) const;
  59. /**
  60. * @brief This is an virtual method that can be overloaded to attend the put request method.
  61. * @param req : This is a reference to the Request.
  62. * @param resp : This is a reference to the Response.
  63. */
  64. virtual void doPut(Request &req, Response &resp) const;
  65. /**
  66. * @brief This is an virtual method that can be overloaded to attend the trace request method.
  67. * @param req : This is a reference to the Request.
  68. * @param resp : This is a reference to the Response.
  69. */
  70. virtual void doTrace(Request &req, Response &resp) const;
  71. };
  72. CWF_END_NAMESPACE
  73. #endif // CONTROLLER_H