text: /**
   *  @file
   *  @copyright defined in eos/LICENSE.txt
   */
  #pragma once
  #include <appbase/application.hpp>
  
  namespace eos {
     using namespace appbase;
  
     /**
      * @brief A callback function provided to a URL handler to
      * allow it to specify the HTTP response code and body
      *
      * Arguments: response_code, response_body
      */
     using url_response_callback = std::function<void(int,string)>;
  
     /**
      * @brief Callback type for a URL handler
      *
      * URL handlers have this type
      *
      * The handler must gaurantee that url_response_callback() is called;
      * otherwise, the connection will hang and result in a memory leak.
      *
      * Arguments: url, request_body, response_callback
      **/
     using url_handler = std::function<void(string,string,url_response_callback)>;
  
     /**
      * @brief An API, containing URLs and handlers
      *
      * An API is composed of several calls, where each call has a URL and
      * a handler. The URL is the path on the web server that triggers the
      * call, and the handler is the function which implements the API call
      */
     using api_description = std::map<string, url_handler>;
  
     /**
      *  This plugin starts an HTTP server and dispatches queries to
      *  registered handles based upon URL. The handler is passed the
      *  URL that was requested and a callback method that should be
      *  called with the response code and body.
      *
      *  The handler will be called from the appbase application io_service
      *  thread.  The callback can be called from any thread and will 
      *  automatically propagate the call to the http thread.
      *
      *  The HTTP service will run in its own thread with its own io_service to
      *  make sure that HTTP request processing does not interfer with other
      *  plugins.  
      */
     class http_plugin : public appbase::plugin<http_plugin>
     {
        public:
          http_plugin();
          virtual ~http_plugin();
  
          APPBASE_PLUGIN_REQUIRES()
          virtual void set_program_options(options_description&, options_description& cfg) override;
  
          void plugin_initialize(const variables_map& options);
          void plugin_startup();
          void plugin_shutdown();
  
          void add_handler(const string& url, const url_handler&);
          void add_api(const api_description& api) {
             for (const auto& call : api) 
                add_handler(call.first, call.second);
          }
  
        private:
          std::unique_ptr<class http_plugin_impl> my;
     };
  
  }
  