1
votes

We are prototyping an architecture in Azure Service Fabric, where we have a number of partitioned stateful services. These services implement a Rest API. We are implementing an API gateway approach as a public interface into our application.

Microsoft have provided and example of this approach in the Service Fabric Wordcount sample code. This sample code only demonstrates forwarding GET requests and a PUT request with no body.

Does anyone have any sample code that demonstrates the best approach to forward POST and PUT requests (with body data) from the gateway to the stateful services?

Thanks in advance.

2
What is it that you think is very different between GET/PUT requests and POST/PUT requests?Michiel Overeem

2 Answers

1
votes

We implemented a HTTP gateway service ourselves as well. To make sure we can have one HTTP gateway for any internal protocol, we implemented the gateway for HTTP based internal services (like ASP.NET WebAPIs) using an ASP.NET 5 middleware. It routes requests from e.g /service to an internal Service Fabric address like fabric:/myapp/myservice by using the ServicePartitionClient and some retry logic from CommunicationClientFactoryBase.

We open-sourced this middleware and you can find it here: https://github.com/c3-ls/ServiceFabric-HttpServiceGateway

There's also some more documentation in the wiki of the project.

0
votes

The only part of the inter-service communication found in the WordCount sample that is Service Fabric-specific is the use of the ServicePartitionClient to resolve the appropriate endpoint URI for the partition. After that, it uses standard HttpWebRequest in the gateway/client and standard ASP.NET WebAPI in the stateful service. You can use existing resources for both to see how to expand it to include content in the body of the requests.