C and C++ web framework. http://rapida.vilor.one/docs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

139 lines
3.1 KiB

/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Copyright 2022 Ivan Polyakov */
#ifndef RAPIDA_ROUTE_HXX_ENTRY
#define RAPIDA_ROUTE_HXX_ENTRY
#include "Request.hxx"
#include "Response.hxx"
namespace rpd {
/*!
* \brief Base class for routes.
*/
class Route {
public:
/*!
* \brief Default constructor.
*
* Creates a new route to handle roquests.
*/
Route() { }
/*!
* \brief Client request handler.
*
* Reads the request method and calls handler for this method.
* \see handle_get for GET requests.
* \see handle_post for POST requests.
* \see handle_put for PUT requests.
* etc.
*
* \note This method will be automatically called.
* You don't need to use it.
*
* \param req Request instance.
* \param res Response instance.
* \param route C rpd_route instance.
*/
static void handle_request(rpd_req *req, rpd_res *res, void *route);
/*!
* \brief Destructor.
*/
virtual ~Route() { }
protected:
/*!
* \brief GET request handler.
*
* Derived class should override this method.
*
* \param req Request.
* \param res Response.
*/
virtual void handle_get(const Request &req, Response &res) = 0;
/*!
* \brief HEAD request handler.
*
* Derived class should override this method.
*
* \param req Request.
* \param res Response.
*/
virtual void handle_head(const Request &req, Response &res) = 0;
/*!
* \brief POST request handler.
* \param req Request.
* \param res Response.
*/
virtual void handle_post(const Request &req, Response &res)
{
res.status(rpd_res_st_not_implemented);
}
/*!
* \brief PUT request handler.
* \param req Request.
* \param res Response.
*/
virtual void handle_put(const Request &req, Response &res)
{
res.status(rpd_res_st_not_implemented);
}
/*!
* \brief DELETE request handler.
* \param req Request.
* \param res Response.
*/
virtual void handle_delete(const Request &req, Response &res)
{
res.status(rpd_res_st_not_implemented);
}
/*!
* \brief CONNECT request handler.
* \param req Request.
* \param res Response.
*/
virtual void handle_connect(const Request &req, Response &res)
{
res.status(rpd_res_st_not_implemented);
}
/*!
* \brief OPTIONS request handler.
* \param req Request.
* \param res Response.
*/
virtual void handle_options(const Request &req, Response &res)
{
res.status(rpd_res_st_not_implemented);
}
/*!
* \brief TRACE request handler.
* \param req Request.
* \param res Response.
*/
virtual void handle_trace(const Request &req, Response &res)
{
res.status(rpd_res_st_not_implemented);
}
/*!
* \brief PATCH request handler.
* \param req Request.
* \param res Response.
*/
virtual void handle_patch(const Request &req, Response &res)
{
res.status(rpd_res_st_not_implemented);
}
};
}
#endif // RAPIDA_ROUTE_HXX_ENTRY