Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Building RESTful Web services with Go

You're reading from   Building RESTful Web services with Go Learn how to build powerful RESTful APIs with Golang that scale gracefully

Arrow left icon
Product type Paperback
Published in Dec 2017
Publisher Packt
ISBN-13 9781788294287
Length 316 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Naren Yellavula Naren Yellavula
Author Profile Icon Naren Yellavula
Naren Yellavula
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Getting Started with REST API Development FREE CHAPTER 2. Handling Routing for Our REST Services 3. Working with Middleware and RPC 4. Simplifying RESTful Services with Popular Go Frameworks 5. Working with MongoDB and Go to Create REST APIs 6. Working with Protocol Buffers and GRPC 7. Working with PostgreSQL, JSON, and Go 8. Building a REST API Client in Go and Unit Testing 9. Scaling Our REST API Using Microservices 10. Deploying Our REST services 11. Using an API Gateway to Monitor and Metricize REST API 12. Handling Authentication for Our REST Services

Rise of REST API with Single Page Applications

You need to understand why Single Page Applications (SPA) are the hot topic today. Instead of building the UI in a traditional way (request web pages), these SPA designs make developers write code in a totally different way. There are many MVC frameworks, like AngularJS, Angular2, React JS, Knockout JS, Aurelia, and so on, to develop web UIs rapidly, but the essence of each of them is pretty simple. All MVC frameworks help us to implement one design pattern. That design pattern is No requesting of web pages, only REST API.

The modern web frontend development has advanced a lot since 2010. In order to exploit the features of Model-View-Controller (MVC) architecture, we need to consider the frontend as a separate entity which talks to the backend only using the REST API (most preferably, REST JSON).

Old and new ways of data flow in SPA

All websites go through the following steps:

  1. Request a web page from the server.
  2. Authenticate and show the Dashboard UI.
  3. Allow the user to modify and save.
  4. Request as many web pages from the server as needed to show individual pages on the site.

But in the SPA, the flow is quite different:

  1. Request the HTML template/s to the browser in one single go.
  2. Then, query the JSON REST API to fill a model (data object).
  3. Adjust the UI according to the data in the model (JSON).
  4. When users modify the UI, the model (data object) should change automatically. For example, in AngularJS, it is possible with two-way data binding. Finally, make REST API calls to notify the server about changes whenever you want.

In this way, communication happens only in the form of the REST API. The client takes care of logically representing the data. This causes systems to move from Response Oriented Architecture (ROA) to Service Oriented Architecture (SOA). Take a look at the following diagram:

 
SPA reduces the bandwidth and improves the site performance.

Why Go for REST API development?

REST services are trivial in the modern web. SOA (which we discuss in more detail later) created an activity space for REST services to take web development to the next level. Go is a programming language from the house of Google for solving the bigger problems they have. It has been eight-plus years since its first appearance. It matured along the way with a developer community jumping in and creating huge scale systems in it.

Go is the darling of the web. It solves bigger problems in an easy way.

One can choose Python or JavaScript (Node) for their REST API development. The main advantage of Go lies in its speed and compile-time error detection. Go is proved to be faster than dynamic programming languages in terms of computational performance by various benchmarks. These are the three reasons why a company should write their next API in Go:

  • To scale your API for a wider audience
  • To enable your developers to build robust systems
  • To invest in the future viability of your projects

You can look at the neverending online debates for more information about REST services with Go. In later chapters, we try to build the fundamentals of designing and writing the REST services.

You have been reading a chapter from
Building RESTful Web services with Go
Published in: Dec 2017
Publisher: Packt
ISBN-13: 9781788294287
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime