1.4.4. HTTP Handlers

There are several types of requests you can send to a HTTP server. The most common ones are the following.

PUT
send some data to a server
GET
query data from a server
POST
a requests that modifies and afterwards returns data (more or less a combination of PUT and GET)
DELETE
delete some remote data

You can add handlers for each of these methods to a HTTP server object. Each handler is usually responsible for a master resource. You can think of a master resource as some sort of directory. Each master resource contains one or more subresources which are similar to files.


  class RpcInfoHandler : public HtmlFormHandler
  {
     RpcInfoHandler()
       : HtmlFormHandler("/rpc-info/") 1
     {
       addSubResource("",           this, &RpcInfoHandler::handle_index); 2
       addSubResource("index.html", this, &RpcInfoHandler::handle_index);
     }

     CppString handle_index(const HtmlFormData &formdata,
                            CppString &mimetype)
     {
       mimetype = "text/html";  3

       return data_for_index;   4
     }
  };

 ...

 http_server.addHttpHandler("get",   5
                            make_methodhandler(rpcinfo,
                                               &RpcInfoHandler::handler));

1

Create a handler for resources below "/rpc-info/".

2

Add subresources for several names which are routed to member methods.

3

Set mime type for returned data.

4

Return the data that belongs to this resource.

5

Add a handler for requests to the above html resource.