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 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 execution based on URI Template, your execution class should inherit from WSF_URI_TEMPLATE_ROUTED_EXECUTION then you need to implement "setup_router". In addition you can inherit from WSF_ROUTED_URI_HELPER and WSF_ROUTED_URI_TEMPLATE_HELPER, in order to call user-friendly routine provided to work easily with uri, or uri-template mapping. the following code is from the step_4 example setup_router do map_uri_agent ("/hello", agent execute_hello, Void) map_uri_template ("/users/{user}/message/{mesgid}", create {USER_MESSAGE_HANDLER}, <<"GET", "POST">>) map_uri_template ("/users/{user}/message/", create {USER_MESSAGE_HANDLER}, <<"GET", "POST">>) map_uri_template_response_agent ("/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 is similar but you precise the accepted request methods * map is similar to previous "agent" variant, but it is using a descendant of WSF_HANDLER to handle the related request. * 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]]