Introduction

About me

I’m one of those people with about two decades of programming experience under my belt. I started optimizing code in the ’90s, discovered PHP in the 2000s, and have built several large-scale projects to date, all while discovering other programming language families like Java, Node.js and ultimately, Go.

I have built numerous APIs for my own content management products. Several products I’ve been involved with as a lead developer have been sold and are used in multiple countries. I’ve written a professional, dedicated API framework, which doubles as a software development kit for the Slovenian national TV and Radio station website, RTV Slovenia. I’ve also been a speaker at several local PHP user group events and conferences.

Why Go?

Go has been on my list for a while now. About a year or two ago, my coworker created a protocol converter that emulates a Memcache server, using Redis as the backend datastore. Since our biggest project has a code base built up over some 13 years, it was preferable to keep the working code as-is, and just replace the software around it as needed. Go made this possible.

One of the reasons for choosing Go was the constant comparison of Go with Node. Node has a much more vocal community, which seems to religiously advocate it. We have carried out several tests in recent months, and Node, while not very hard to start development with, had poorer performance than pretty much everything except PHP. I’m not saying that Go is better than Node, or that anything is better than anything else, but from what we’ve seen, it seems advisable to skip Node.js and go straight to Go. This might change as ES6 and ES7 get more traction - but there are immediate benefits of switching to Go. If you don’t want to move from Node.js, this book is not for you. If you have an open mind - find out what Go can do.

Who is this book for?

This book is for senior developers who might not have had a chance to try Go, but are familiar with concepts of API development in languages like PHP or Node. Any reader must have a good understanding of REST APIs and server architecture. While I’ll try to make everything as clear as possible, realize that if you’re a novice programmer, there might be a gap between what you know, and what I’m trying to explain here.

I’m not going to be explaining the Go programming language in detail. I’m going to be diving head first into using it with just a note here and there. This is why familiarity and strong knowledge of programming concepts are required.

In the book, I will cover these subjects:

  1. Setting up your environment
  2. Data structures
  3. Organizing your code
  4. Encoding and decoding JSON
  5. Serving HTTP requests
  6. Parallel fetching of data
  7. Using external services (Redis)
  8. Using external services (MySQL)
  9. Test driven API development
  10. Your first API
  11. Running your API in production
  12. Resources

Covering these concepts should give you a strong foundation for your API implementation. The book doesn’t try to teach you Go; the book tries to give you a strong software foundation for APIs, using Go.

How should I study it?

Through the book, I will present several examples on how to do common things when developing APIs. The examples are published on GitHub, you can find the link in the last chapter of the book.

You should follow the examples in the book, or you can look at each chapter individually, just to cover the knowledge of that chapter. The examples are stand-alone, but generally build on work from previous chapters.