Request Chaining
Request Chaining...Another kind of DesignPattern.
I will not be talking much about it as you all already be aware of such pattern or can implement as per the given idea below-
So what it is?
Where can I use it?
What benefits can I get from such Pattern?
Lets discuss on that one by one below -
1) It is nothing special, it is just like combining 2 or more requests in single request without the user being aware that behind this there multiple individual requests being processed. You will get more clarity once we discuss on the benefits below.
2) As we are talking about requests, you might have got idea that we are talking about WebServices & I will be taking this idea in terms of REST here.
3) So benefits.
In REST, you will be creating various services like - Get, Put, Post, Delete, I am not talking about others as most people don't even touch those.
Now, your team member, A created one Get service which returns list of Books.
Your another team member, B created Post another service which posts the provided input to some DB service to persist.
So currently as a user I have to first call Get service to get the list of Books then I will Post service to persist that list.
Hmmm, I being a user, I don't like this much of work. Its good you provided Get service for me to see the list of Books.
You also provided me one Post service to persist the data I want to.
But I expect some service that can show the list of Books & also persist that, why do I need to copy the data from Get service & post it to another service to persist the data. You can do persist the list shown to me, directly.
You being a good Soul, understands this & say that you will provide another service to me to get this done in single shot.
But, wait a minute, You said yes, but who will make this change?
Whether it should be the responsibility of A or B? Does anyone of them need to be aware about the other one?
Both A and B are individual contributor & why do they need to interact with each other?
So, again you being a Smart Engineer, understands it & come up with idea to combine both these services into one service which you can give to me to use. And this is called Request Chaining. Here both A & B need not to be aware about each other & no such change is required on their side as it is a separate Aspect without polluting the underlying services.
I will not be talking much about it as you all already be aware of such pattern or can implement as per the given idea below-
So what it is?
Where can I use it?
What benefits can I get from such Pattern?
Lets discuss on that one by one below -
1) It is nothing special, it is just like combining 2 or more requests in single request without the user being aware that behind this there multiple individual requests being processed. You will get more clarity once we discuss on the benefits below.
2) As we are talking about requests, you might have got idea that we are talking about WebServices & I will be taking this idea in terms of REST here.
3) So benefits.
In REST, you will be creating various services like - Get, Put, Post, Delete, I am not talking about others as most people don't even touch those.
Now, your team member, A created one Get service which returns list of Books.
Your another team member, B created Post another service which posts the provided input to some DB service to persist.
So currently as a user I have to first call Get service to get the list of Books then I will Post service to persist that list.
Hmmm, I being a user, I don't like this much of work. Its good you provided Get service for me to see the list of Books.
You also provided me one Post service to persist the data I want to.
But I expect some service that can show the list of Books & also persist that, why do I need to copy the data from Get service & post it to another service to persist the data. You can do persist the list shown to me, directly.
You being a good Soul, understands this & say that you will provide another service to me to get this done in single shot.
But, wait a minute, You said yes, but who will make this change?
Whether it should be the responsibility of A or B? Does anyone of them need to be aware about the other one?
Both A and B are individual contributor & why do they need to interact with each other?
So, again you being a Smart Engineer, understands it & come up with idea to combine both these services into one service which you can give to me to use. And this is called Request Chaining. Here both A & B need not to be aware about each other & no such change is required on their side as it is a separate Aspect without polluting the underlying services.