Skip to content

FireStorm Object

Hayley edited this page Sep 12, 2020 · 6 revisions

The FireStorm object is the core logic to the framework. It registers your routes and error pages as well as runs the web server. For an example

int main() {
  FireStorm()
    .add_route(new UserDefinedRoute())
    .add_route(new AnotherUserDefinedRoute())
    .ignite(5000);
  return 0;
}

Registering routes

Routes can be registered using the add_route() method (see above for an example). The order in which the routes are added is preserved meaning that they will be executed in the same order when the server receives a request.

Running the web server

The ignite() method can be used to start the web server. The ignite() method has the following signature

void ignite(unsigned int port);

where port is the TCP port to listen for requests on (we recommend using 5000).

Custom error pages

All custom error page handlers must be a valid ErrorFn where ErrorFn is defined as

using ErrorFn = Response (*)();

For an example the default 404 handler is as follows

Response not_found_fn() { 
  return plain("Not Found", HTTP_STATUS_NOT_FOUND);
}

Custom error pages can be registered by passing a ErrorFn to the corresponding FireStorm method.

All the possible methods are

FireStorm bad_request(ErrorFn fn);
FireStorm unauthorized(ErrorFn fn);
FireStorm forbidden(ErrorFn fn);
FireStorm not_found(ErrorFn fn);
FireStorm method_not_allowed(ErrorFn fn);
FireStorm internal_server_error(ErrorFn fn);
FireStorm not_implemented(ErrorFn fn);
FireStorm service_unavailable(ErrorFn fn);
Clone this wiki locally