Closed marcinczeczko closed 7 years ago
Approved.
This is handlebars snippet in /userProfile.html
<script type="text/x-handlebars-template" data-api-type="templating"
data-service-profile="getprofile" data-params-profile="{'path': '/service/user/{_request.headers.userId}'}"
data-action-modify="updateprofile" data-params-modify="{'path': '/service/user/{_request.headers.userId}'}">
<form action="">
{{#if modify.fail}}
<intput type="text" name="firstname" value={{_request.params.firstname}}>
{{else}}
<intput type="text" name="firstname" value={{profile.firstname}}>
{{/if}}
{{#if modify.fail}}
<intput type="text" name="lastname" value={{_request.params.lastname}}>
{{else}}
<intput type="text" name="lastname" value={{profile.lastname}}>
{{/if}}
<input type="submit" value="Submit">
</form>
</script>
User submit form with incorrect firstname and lastname:
POST /userProfile.html
{
firstname: firstnamevalue
lastname: lastnamevalue
}
Service returned HTTP 400 with body
{
"fail": "true"
}
Rendered page looks like:
<form action="">
<intput type="text" name="firstname" value="firstnamevalue">
<intput type="text" name="lastname" value="lastnamevalue">
<input type="submit" value="Submit">
</form>
User updates values and submit form once again:
POST /userProfile.html
{
firstname: Firstnamevalue
lastname: Lastnamevalue
}
Validation ok, service returned HTTP 200 with body:
{
"fail": "false"
}
Rendered page looks like:
<form action="">
<intput type="text" name="firstname" value="Firstnamevalue">
<intput type="text" name="lastname" value="Lastnamevalue">
<input type="submit" value="Submit">
</form>
This solution assumes that POST request is handled before GET request (new approach for forms). As we have separate methods POST and GET requests we need to reflect it in handlebars with #if statements.
Small comoment. data-action and data-action-params attributes are enough. Don't need to have extra namespace for action. It can be just one on the snippet. In handlebars it can be available simply as {{action.....
Agree. POST must be always processed as first. But I'd not touch this in this ticket. It's enough, let's address it in forms ticket and here keep existing behavior. Simply one step at a time ;)
Knot.x snippets should be able to talk with services through Vert.x event bus only. It implies few design changes to Knot.x that will simplify understanding its architecture. Additionally, such decision does not limit to HTTP protocol of the target services, because event bus service that Knot.x is going to use (from now on) can be treated as extension point. Out of the box Knot.x will be shipped with service that's a bridge between template engine and HTTP based target service. Depending on needs a new event bus based sevice can be implemented to talk using any other communication method, e.g. TCP, ActiveMQ and so on...
In this Story a following aspects need to be implemented:
1. Services configuration - engine JSON configuration
services section of engine configuration
Where:
2. Template markup syntax updated
The template syntax don't need to carry uri or http method name with it, it should have form as follows:
Additionally, some parameters to the service might need to be provided on markup level (e.g. through CMS), those need to be provided using new elements
Where namespace is the namespace of on which results will be accessible. E.g.
Params related to the service will be send to adapter service together with request and config
3. Template engine logic
Template engine verticle need to be modified to address following aspects:
4. Create configurable event bus service - To keep same set of functionality
A new verticle in core to be created, let's call it CoreServiceAdapter.
Where: config.path - is the target path to the service. It supports syntax of parameterized values as described here Parametrized service calls. However it should be extended - see next point. snippet - is the json object with parameters from snippet (tag data-params- )
5. Parametrized service calls
As stated above, parametrized service calls mechanism will be reflected in core service adapter. However it require extra feature that allows to form an URI using parameters from the snippet params tag. E.g., assuming the core adapter will get following data
The functionality must support snippet to resolve any value inside that json object. Snippet above is self explainable.
6. Core standalone & example updated
7. Documentation updated
Wiki documentation need to reflect changes:
See the conceptual diagram below how the message and processing flow might look