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)

SQLite3 basics and CRUD operations

SQLite3 is a lightweight, file-based SQL database. It is very useful to quickly build persistence for API. It leverages the SQL language and a relational database. In this section, we see how to interact with SQLite3 from Go.

All SQLite3 operations are going to be done using the go-sqlite3 library. We can install that package using the following command:

go get github.com/mattn/go-sqlite3

The special thing about this library is that it uses the internal sql package of Go. We usually import database/sql and use SQL to execute database queries on the database (here, SQLite3):

import "database/sql"

Now, we can use the following steps to create a database driver and then execute the SQL commands on it using the Query method:

  1. Let's create a file in this path:
touch -p $GOPATH/src/github.com/git-user/chapter4/sqliteExample/main.go
...