I create a server which is listening on port 7000. I want my server can use function
listener.support(methods::POST, handle_post1);//if this is the first msg I receive
listener.support(methods::POST, handle_post2);//if this is the second msg I receive
Your listener will handle the request on the server side. With
support() you don't handle a specific request but you add a handler for all subsequent requests.
In your question, you intend to handle requests differently, depending on the relative order of the request: the first should be handled by
handle_post1 and the second with
handle_post2. This means that you want the handling to depend on the server state.
If you'd really like to pursue, you could imagine using a
handle_dispatcher() that maintains some static variable that counts the requests and delegates further to
handle_post2 depending on the state. But this is really not advised. The goal of REST is that different requests could be dispatched to different servers, in which case your dispatcher would not produce the expected results. If you don't want to embrace this approach, you should then use a stateful framework.