Closed parthibd closed 5 years ago
Hi @parthibd, there are many ways to pre/post process requests using this library. Can you describe with an example you particular use case so I can offer you a proper solution?
Thanks.
Say I have two endpoints in two different services /custdetails & /orders . I want to call /user/1/details . What I really want is to call there two endpoints ,get the response and merge them . Is this possible ?
It is possible, I will get back to you with an example ASAP.
Thanks a lot . I am planning to add features like loading config from a file ( most probably json/yml?) , adding a service discovery manager .
Any updates ? :)
Hi @parthibd, all contributions are welcome here. Of course it would be great to have proper examples and details on your proposals before you actually start working on it.
Thanks for collaborating!
Say I have a local endpoint like this "/user/:id/details"
Now I want to aggregate I over two service endpoints
{
"path":"/user/:id/details",
"aggregate":true,
"aggregations":[
{
"service":"service1",
"endpoint":"/userdetails/:id"
},
{
"service":"service2",
"endpoint":"/orders/:id"
}
]
}
Is this possible ?
How should I go about implementing it ?
I think you missed the target property names on the aggregations endpoints ;)
Such developments can be plug-in into the the proxy hooks:
hooks: {
async onRequest (req, reply) {
// // we can optionally reply from here if required
// reply.send('Hello World!')
//
// return true // truthy value returned will abort the request forwarding
},
onResponse (req, reply, res) {
// do some post-processing here
// ...
// forward response to origin client once finished
reply.send(res)
}
// other options allowed https://github.com/fastify/fastify-reply-from#replyfromsource-opts
}
Here I also believe that such extensions should not land into the core, build them as separated modules. Afterward those will be properly referenced in here.
Thanks.
Sorry , my bad :) . How should I go ahead to implementing it ? Your guidance will be immensely helpful.
Create a new module that is able to transform high level routes configurations like you propose into low level k-fastify-gateway
compatibility.
I can create an initial implementation here if you like, as soon as I get some free time.
Regards
I got you . So basically you mean the new module should be a layer above the gateway . I get the idea, but can you just give me some sample so that I will know I am going into the right direction ?
Thanks .
How do I make aggregated requests ?