Web framework C++  2.0.0
Simple web framework on c++ designed to easily create web pages, etc
Public Member Functions | List of all members
App Class Reference

The main class of the framework. Each object of this class is an independent web-application, which could be configured by handlers, middleware etc. More...

#include <app.h>

Collaboration diagram for App:
Collaboration graph

Public Member Functions

 App (const char *ip="127.0.0.1", int port=80, bool isIPv6=false, const char *logFilePath=nullptr)
 
 App (InitParams &params)
 
 ~App ()
 
bool init ()
 
void addHandler (Handler *handler)
 
void addPermanentlyRedirect (const char *uri, const char *target)
 
void addTemporaryRedirect (const char *uri, const char *target)
 
void addRedirect (const char *uri, const char *target, int code)
 
void addMiddleware (Middleware *middleware)
 
bool run ()
 

Detailed Description

The main class of the framework. Each object of this class is an independent web-application, which could be configured by handlers, middleware etc.

This class implements web-application, which is running on given and port. It supports IPv6 and can capture log in the file if given. Use Handlers, Middleware and set Redirects to adjust it.

Constructor & Destructor Documentation

App::App ( const char *  ip = "127.0.0.1",
int  port = 80,
bool  isIPv6 = false,
const char *  logFilePath = nullptr 
)
explicit

Create a new web application, which is only adjusted to ip address. You can init this and add some handlers etc. to run this

Parameters
iptext representation of ip address, like 127.0.0.1 or 0:0:0:0:0:0:0:1 (if IPv6)
portport in range [0, 65535]
isIPv6set true, if param ip is version 6
logFilePathif you want to create log file, give a file path, or null otherwise
App::App ( InitParams params)
explicit

Create a new web application, by command line arguments using InitParams object

Parameters
paramsGive an object params, which was created by InitParams class from command line arguments
App::~App ( )

Destructor delete all added handlers and all middleware

Member Function Documentation

void App::addHandler ( Handler handler)

To configure your application create and add some handlers

Parameters
handlerobject of class Handler (could be inherited) with overridden function exec
void App::addMiddleware ( Middleware middleware)

Add object of class Middleware, which has got overridden function exec to do given operations on every request. All handlers could access to any middleware and perform adjusted actions.

Parameters
middlewareobject of class Middleware (could be inherited)
void App::addPermanentlyRedirect ( const char *  uri,
const char *  target 
)

Add redirection, which is meant to last forever. The original URL should not be used anymore and that the new one is preferred. Search engine robots trigger an update of the associated URL for the resource in their indexes. (HTTP code 301)

Parameters
urioriginal uri path, which is deprecated (outdated)
targetnew uri address of mentioned page
void App::addRedirect ( const char *  uri,
const char *  target,
int  code 
)

To adjust any redirection using status code. For example, 304 (Not Modified) redirects a page to the locally cached copy, and 300 (Multiple Choice) is a manual redirection: the body, presented by the browser as a Web page, lists the possible redirection and the user clicks on one to select it.

Parameters
urioriginal uri path, which is deprecated (outdated)
targetnew uri address of mentioned page
codeHTTP code redirection status of response
void App::addTemporaryRedirect ( const char *  uri,
const char *  target 
)

Temporary redirect can be used, if for some time the requested resource cannot be accessed from its canonical location, but it can be accessed from another place. Search engine robots don't memorize the new, temporary link. Temporary redirection are also used when creating, updating and deleting resources to present temporary progress pages.

Parameters
urioriginal uri path, which is deprecated (outdated)
targetnew uri address of mentioned page
bool App::init ( )

Use this function to open socket for listening on declared ip address and port. After creating on object you should use this function to startup web-socket

Returns
true if ip address and port were valid and available, false - otherwise, please, use another address to continue
bool App::run ( )

Start listening for request. This method startup the system, where on every request from clients all added handlers and middleware create a response and send it to client.


The documentation for this class was generated from the following file: