HTTP Server Requests Handlers

Handlers

There are three handlers included in the HTTPServer package:

  • SimpleHandler
  • FSHandler
  • RPCHandler

You can also create a custom handler by simply inheriting the HTTPRequestHandler class.

HTTPRequestHandler base class

To add a handler class to a server, simply use the server's addHandler method:

template<typename T>
void addHandler(const char* path)

Append an handler of type T to the handlers list, for requests of path starting with path.

Example:

svr.addHandler<SimpleHandler>("/hello");

SimpleHandler

This is a basic handler which returns an hello world message.

Reference

No specific method for this handler.

FSHandler

This handler allows you to server files from a filesystem, such as the mbed's drive or a SD Card. Note that to use it you have to instantiate the file system yourself.

Reference

static void mount(const string& fsPath, const string& rootPath)

Make the files located under fsPath available under the server's rootPath directory.

RPCHandler

This handler allows you to execute RPC requests using GET commands.

Reference

No specific method for this handler.

Examples

The second example of the HTTP Server wiki page uses all-three handlers.


All wikipages