Book Image

Hands-On RESTful Web Services with Go - Second Edition

By : Naren Yellavula
Book Image

Hands-On RESTful Web Services with Go - Second Edition

By: Naren Yellavula

Overview of this book

Building RESTful web services can be tough as there are countless standards and ways to develop API. In modern architectures such as microservices, RESTful APIs are common in communication, making idiomatic and scalable API development crucial. This book covers basic through to advanced API development concepts and supporting tools. You’ll start with an introduction to REST API development before moving on to building the essential blocks for working with Go. You’ll explore routers, middleware, and available open source web development solutions in Go to create robust APIs, and understand the application and database layers to build RESTful web services. You’ll learn various data formats like protocol buffers and JSON, and understand how to serve them over HTTP and gRPC. After covering advanced topics such as asynchronous API design and GraphQL for building scalable web services, you’ll discover how microservices can benefit from REST. You’ll also explore packaging artifacts in the form of containers and understand how to set up an ideal deployment ecosystem for web services. Finally, you’ll cover the provisioning of infrastructure using infrastructure as code (IaC) and secure your REST API. By the end of the book, you’ll have intermediate knowledge of web service development and be able to apply the skills you’ve learned in a practical way.
Table of Contents (16 chapters)

Long-running task design

So far, we've learned about the basics of queuing and how to delay jobs. Now, we're going to design a solution to a problem regarding asynchronous APIs. The problem is that we want to build a system that can handle requests for the following scenarios:

  • The server should save information to the database as one operation.
  • It should send an email to the given email address.
  • It should perform a long-running job and POST the result to a callback. This is known as a web-hook.

Let's say these three operations are asynchronous and long-running. We need a mechanism to facilitate a long-running process that has the following characteristics:

  • The client can fire an API and receive a job ID back.
  • The job is pushed onto a queue with the respective message format.
  • A worker picks the job and starts performing it.
  • Finally, the worker saves the result...