I'm designing microservice architecture as below:
Gateway uses Ocelot to forward requests. I would like to change the body in request received from mobile device on gateway side and add inside the body new GUID. Microservices uses CQRS pattern, so command shouldn't returns anything. I implemented custom middleware to change DownstreamContext:
public override async Task Execute(DownstreamContext context)
{
var secondRequest = JObject.Parse(await context.DownstreamRequest.Content.ReadAsStringAsync());
secondRequest["token"] = "test";
secondRequest["newId"] = Guid.NewGuid();
context.DownstreamRequest.Content = new StringContent(secondRequest.ToString(), Encoding.UTF8);
await this.Next(context);
}
I debugged this and content of DownstreamRequest before call await this.Next(context); is changed, but request incoming to microservice is not changed. Is there any way to change request in gateway and forward this request to microservice in a changed form?