示例#1
0
static void PrepareTheAPI(Messaging::Service& service)
{
	logs.debug() << "preparing protocol";
	// note: contrary to the object `service`, `myapi` is not thread-safe
	Messaging::Protocol* myapi = new Messaging::Protocol();
	// retrieving the default schema
	Messaging::Schema& schema = myapi->schema();

	// method: hello_world
	schema.methods.add("hello_world")
		.brief("Always answer 'hello world to any request'")
		.option("http.method", "GET")
		.invoke(& APIHelloWorld);

	// method: sum
	schema.methods.add("sum")
		.brief("Computes the sum of two numbers")
		.option("http.method", "GET")
		.param("a", "First operand", "0")
		.param("b", "Second operand", "0")
		.invoke(& APISum);

	// -- Switching to the new protocol
	// note: The method `protocol()` must be call to make any modification to
	//   the protocol visible, and can be called anytime, even if started
	//   (useful for reloading the service while running)
	// note: this method will take ownership of the pointer, thus the pointer
	//   must not be used after this statement
	service.protocol(myapi);
}
示例#2
0
static void PrepareTransports(Messaging::Service& service)
{
	logs.debug() << "preparing transports";
	service.transports.add("*", 6042, new Messaging::Transport::REST::Server());
}