Back to the [[step_3.wiki|step 3]] or go to the [[README.wiki|index]] ---- = Tutorial Step 4 = * '''Goal''': Learn how to use Router (i.e: url dispatcher) * '''Requirements''': ** know how to compile with Eiffel (EiffelStudio). ** [[step_3.wiki|Previous step ]] completed == "hello" project == * Let's start from the "hello" project * you will learn how to use the req: WSF_ROUTER component * See the hello project from [[step_4|step #4]] folder * You can find code in [[step_4]] folder : To get a routed service based on URI Template, your service application class should inherit from WSF_URI_TEMPLATE_ROUTED_SERVICE then you need to implement "setup_router", the following code is from the step_4 example setup_router do router.map_agent ("/hello", agent execute_hello) router.map_with_request_methods ("/users/{user}/message/{mesgid}", create {USER_MESSAGE_HANDLER}, <<"GET", "POST">>) router.map_with_request_methods ("/users/{user}/message/", create {USER_MESSAGE_HANDLER}, <<"GET", "POST">>) router.map_agent_response_with_request_methods ("/users/{user}/{?op}", agent response_user, <<"GET">>) end * map_agent is used to handle the url /hello with the feature "execute_hello" * map_agent_response_with_request_methods is similar but you precise the accepted request methods * map and map_with_request_method are similar to previous "agent" variant, but it is using a descendant of WSF_HANDLER to handle the related url. * In this example, we use the URI Template router, this allows to define the route using resource like /user/{user} , and then you get access to the "user" data from the WSF_REQUEST.path_parameter or using the context argument passed for the execute or response handler. * The example also includes basic notions of url, html encoding, check the hello.ecf to see the added libraries (http to get easy access to the http status code, encoder for simple encoding components) ---- Back to the [[step_3.wiki|step 3]] or go to the [[README.wiki|index]]