<p>Go is pretty good for creating web APIs. Are there any projects to learn best practices for creating web APIs.</p>
<p>Update:
A quick search on github showed me <a href="https://github.com/dhax/go-base/">https://github.com/dhax/go-base/</a> .It seem pretty great, it is more of a boilerplate but good enough for me. </p>
<hr/>**评论:**<br/><br/>NotFromReddit: <pre><p>Not based on Go, there there is a book called <a href="https://apisyouwonthate.com/">APIs You Won't Hate</a>. It's about API design.</p></pre>chilladx: <pre><p>Not exactly a Go project, but nice reading when designing an API: <a href="https://cloud.google.com/apis/design/" rel="nofollow">https://cloud.google.com/apis/design/</a>.
And this post on building an API with gRPC, in Go: <a href="https://medium.com/pantomath/how-we-use-grpc-to-build-a-client-server-system-in-go-dd20045fa1c2" rel="nofollow">https://medium.com/pantomath/how-we-use-grpc-to-build-a-client-server-system-in-go-dd20045fa1c2</a></p></pre>Mittalmailbox: <pre><p>I dont understand advantages of gRPC really. Is it supposed to be used for microservices only or it has other advantages also.</p></pre>chilladx: <pre><p>(note: I'm talking about gRPC with protobuf)
First of all, I like the code generation. Not only you build a server, but also you generate the code for the client, and all that just by describing your messages and services.
I also love the fact I don't need to handle serialization and deserialization of data (so boring when building an API, and so prone to errors).
It's pretty cool to enjoy HTTP/2 server (think streaming). I like the ease to integrate authentication at the transport level. And building a full server with encryption (SSL), identification (with gRPC metadata), (de)serialization of data with just a few lines of code.
And should one client be incompatible with gRPC, you can have a gateway to a REST interface pretty quickly too.</p>
<p>So, imho, gRPC works perfectly for microservices, but not only. It really depends on the client, I would say, but there too, there's room for it. </p></pre>Thaxll: <pre><p>You have a real contract between the client and the server, in REST it's like oops I added this field now the API is broken, or how do I parse the response ect ... You have the same schema for talking and it's very powerful.</p></pre>HectorJ: <pre><p>There is openAPI for REST contracts</p></pre>10gistic: <pre><p>Serialization efficiency is one of the huge advantages. You describe your message types and gRPC builds binary encoders/decoders that are much faster to serialize/deserialize from/to native memory than, e.g., JSON strings</p>
<p>On top of that, client generation and server stub generation makes cross-language support a little easier, and gives you familiar types for whatever language you're using. In this way, you get a little more reusability for mostly free as long as you're using supported languages.</p>
<p>There are probably a few more benefits, like circuit breakers in the generated code, but in my opinion, the above two are the major selling points that interest me.</p></pre>cirowrc: <pre><p>I'd stick with something like swagger / OpenAPI nowadays. <a href="https://github.com/go-swagger/go-swagger" rel="nofollow">go-swagger</a> does a pretty good job of generating both client and server code from a swagger specification.</p>
<p>The idea is that you create a <code>api.yml</code> file that you declaratively describe the responses and endpoints of your application and then let <code>go-swagger</code> generate the boilerplate for you. For the server-side code all you gotta do is implement the methods that the interface generated by <code>go-swagger</code> gives you and then you're done. </p>
<p>Let me know if you need more info. I've used it once and it really liked.</p></pre>diegobernardes: <pre><p>This is a project i'm working on: <a href="https://github.com/diegobernardes/flare" rel="nofollow">https://github.com/diegobernardes/flare</a>
It's heavy inspired by <a href="https://medium.com/@benbjohnson/standard-package-layout-7cdbc8391fc1" rel="nofollow">https://medium.com/@benbjohnson/standard-package-layout-7cdbc8391fc1</a> and <a href="https://github.com/marcusolsson/goddd" rel="nofollow">https://github.com/marcusolsson/goddd</a></p></pre>Probotect0r: <pre><p>To add on to this question, are there any go libraries that take care of setting up basic crud operations for you? I mean all the way from the rest endpoints to the database code.</p>
<p>I tried go for a project once and it was fun to use, but having to write all that basic code for all projects seemed tedious. For example, I work with Java and Spring at work and I can set up a full crud API in a couple of lines of code with it.</p></pre>monkey-go-code: <pre><p>I use C# at work. So when I went to learn golang I tried to apply the same things. Basically I have a controller for each set of end points. A component for application logic and a repository layer for actual database access. That pattern works pretty good for me. I’ve heard of people copying the patterns they used in Ruby too. </p></pre>ChiefDetektor: <pre><p>portainer (<a href="http://www.portainer.io" rel="nofollow">www.portainer.io</a>) is open source. It's an webfrontend for docker. Might be interesting for u. </p></pre>brokedown: <pre><p>If you don't mind an opinionated stack, you might look at Buffalo. <a href="https://www.youtube.com/watch?v=75NjCfLLftw" rel="nofollow">https://www.youtube.com/watch?v=75NjCfLLftw</a></p>
<p>I've watched part of the video and it seems like it does bring some value, but haven't gotten beyond basic dabbling.</p></pre>applicativefunctor: <pre><p>By definition, since it has to be written in go, no.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传