<story><title>REST Servers in Go: Part 1 – standard library</title><url>https://eli.thegreenplace.net/2021/rest-servers-in-go-part-1-standard-library/</url></story><parent_chain><item><author>0xbkt</author><text>I would probably go with gRPC + grpc-gateway[1] instead. Declaring your services and models in proto files, annotating your services with google.api.http to help grpc-gateway scaffold your HTTP base. Then just implement your services from the interface generated by grpc-go. You can even register your gRPC services to grpc-gateway without actually bringing up a gRPC server. You finally end up having your exact data models injected to your service handlers. Thus, you don&amp;#x27;t  have to repeat yourself preparing the groundwork to call into your services.&lt;p&gt;This is mostly the way today services in big OSS projects are exposed outside for consumption in a RESTful style. One exception I know of is sourcegraph&amp;#x2F;sourcegraph.&lt;p&gt;[1] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;grpc-ecosystem&amp;#x2F;grpc-gateway#usage&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;grpc-ecosystem&amp;#x2F;grpc-gateway#usage&lt;/a&gt;</text></item></parent_chain><comment><author>hardwaresofton</author><text>It feels like an ugly hack that grpc-gateway sits on top of gRPC to support HTTP&amp;#x2F;1 when gRPC could have been written to support HTTP&amp;#x2F;1 and HTTP&amp;#x2F;2 from the beginning. Roughly, gRPC ~= protobuf (serialization &amp;amp; schema enforcement) + HTTP&amp;#x2F;2 + non-standard HTTP&amp;#x2F;2 (trailers, etc), and it is hard to believe that just as they standardized the non-standard bits, they couldn&amp;#x27;t have found a way to work over HTTP&amp;#x2F;1 (or HTTP&amp;#x2F;1.1 at least) with the flexibility available there.&lt;p&gt;gRPC feels to me like a violation&amp;#x2F;break in expectations of how the layers of abstraction are supposed to work -- gRPC works &lt;i&gt;over&lt;/i&gt; HTTP&amp;#x2F;2, and it&amp;#x27;s weird that it translates a lower level (HTTP&amp;#x2F;1) at a higher level (gRPC) to re-encode it into something at the lower level. An appropriately robust protocol would simply support both lower levels of abstraction if it wanted to (and they were widespread in daily use), right?&lt;p&gt;The only places I feel like I see this kind of layer violations are in lower level networking and it generally just makes everything worse and more complicated there. Of course, I know that gRPC + gateway is actually not a huge deal in practice -- you&amp;#x27;ve got reverse proxies like envoy that will do it for you automatically[0], but it just... doesn&amp;#x27;t sit great. The benefits of gRPC are not to be sneezed at (better performance, strict typing at the protocol level, schema enforcement, bidirectional streaming, etc), but it feels like it could have accomplished a lot of those goals without throwing out HTTP&amp;#x2F;1.1 completely (and then that machinery could have been reused to support HTTP&amp;#x2F;3).&lt;p&gt;[0]: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;www.envoyproxy.io&amp;#x2F;docs&amp;#x2F;envoy&amp;#x2F;latest&amp;#x2F;configuration&amp;#x2F;http&amp;#x2F;http_filters&amp;#x2F;grpc_http1_bridge_filter&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;www.envoyproxy.io&amp;#x2F;docs&amp;#x2F;envoy&amp;#x2F;latest&amp;#x2F;configuration&amp;#x2F;ht...&lt;/a&gt;</text></comment>
<story><title>REST Servers in Go: Part 1 – standard library</title><url>https://eli.thegreenplace.net/2021/rest-servers-in-go-part-1-standard-library/</url></story><parent_chain><item><author>0xbkt</author><text>I would probably go with gRPC + grpc-gateway[1] instead. Declaring your services and models in proto files, annotating your services with google.api.http to help grpc-gateway scaffold your HTTP base. Then just implement your services from the interface generated by grpc-go. You can even register your gRPC services to grpc-gateway without actually bringing up a gRPC server. You finally end up having your exact data models injected to your service handlers. Thus, you don&amp;#x27;t  have to repeat yourself preparing the groundwork to call into your services.&lt;p&gt;This is mostly the way today services in big OSS projects are exposed outside for consumption in a RESTful style. One exception I know of is sourcegraph&amp;#x2F;sourcegraph.&lt;p&gt;[1] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;grpc-ecosystem&amp;#x2F;grpc-gateway#usage&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;grpc-ecosystem&amp;#x2F;grpc-gateway#usage&lt;/a&gt;</text></item></parent_chain><comment><author>whoisjohnkid</author><text>Have you looked into goa design[1]? You define your services with a contract via their DSL and it generates all code for you as well; has some nice validation options out of the box.
  - similar to grpc gateway you just need to conform to the generated code’s service interface.&lt;p&gt;I believe it supports, http, websocket and grpc.&lt;p&gt;[1]&lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;goadesign&amp;#x2F;goa&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;goadesign&amp;#x2F;goa&lt;/a&gt;</text></comment>