How to write api

agolangf · · 568 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Okay so I&#39;m trying to do this project some redditor suggested as a small resume piece. </p> <blockquote> <p>Ok, learn Golang <a href="https://tour.golang.org/welcome/1" rel="nofollow">https://tour.golang.org/welcome/1</a> and use it to write a web-facing website and API hosted on DigitalOcean - the API should accept some text through post request and then return an anagram of that text. You can get as fancy as you want with detecting anagrams.</p> </blockquote> <p>In a separate correspondence, here is what the redditor said.</p> <blockquote> <p>You&#39;ll need to get into JavaScript and probably jQuery. It&#39;s pretty basic though; Golang acts as a back end API and the front end makes requests to that and displays the results. As for serving the pages, you can host them from Go or set up Nginx or something to serve them and also proxy the API.</p> </blockquote> <p>I don&#39;t really understand how to go about doing this.</p> <p>So far, I&#39;ve gone through part of the freeCodeCamp front end certificate which involved HTML, CSS with Bootstrap, and Javascript with jQuery, so I have some basic working knowledge of those languages/libraries. I made a simple random quote generator with some quote API. I&#39;ve also read up on APIs and stuff on the Mozilla Developer guide <a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs" rel="nofollow">here</a>.</p> <p>So that&#39;s really all I know so far. I&#39;d like some guidance on my steps moving forward. Should I just learn some Go from here? Since I&#39;m going to be using Go for the backend, I don&#39;t need to learn Node.js or Express or anything like that right?</p> <p>Honestly, I don&#39;t really even know what goes into writing an API. I&#39;m not really sure how to connect the front end stuff (the HTML, CSS, and Javascript) with my backend stuff in Golang either. </p> <p>For now, I just plan on learning some Go. Any ideas?</p> <hr/>**评论:**<br/><br/>Pawda: <pre><p>Yea you don&#39;t need Node.js nor Express. Those are used on the server side where you&#39;re going to use Go for it.</p> <p>I would suggest you to use a framework that is doing a lot of work for you and will provide you with some examples:</p> <p>(IMO), here is an easy one to start with: <a href="https://echo.labstack.com/middleware/static" rel="nofollow">https://echo.labstack.com</a></p></pre>pleasegivemesomethin: <pre><p>Thank you. I still need to get basic Go down first, but I&#39;ll check that out as soon as I feel ready.</p></pre>Pawda: <pre><p>If you&#39;re already familiar with any programming language or you feel like getting dazed by reading the doc, what&#39;s usually works is to learn these news basics by actually writing code.</p> <p>Setup your environment and write down the examples you find interesting, don&#39;t copy paste them, try to understand how it works and how to tweak it towards your goal.</p> <p>Good luck :)</p></pre>kittuov: <pre><p>I think you should make the go app first. Just API and no html.</p> <p>You can use postman to test your API.</p> <p><a href="https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en" rel="nofollow">https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en</a></p> <p>Try to do it without any framework or libs. Just to get basic understanding. Then you can take a call on using some framework. </p> <p>Once you get here I think you can finish by googling jQuery post request. </p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

568 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传