Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Modern REST API Development in Go
  • Table Of Contents Toc
Modern REST API Development in Go

Modern REST API Development in Go

By : Jesús Espino
close
close
Modern REST API Development in Go

Modern REST API Development in Go

By: Jesús Espino

Overview of this book

Modern REST API Development in Go is a hands-on guide to understanding and applying REST principles using Go’s powerful standard library. In an era where interconnected systems demand robust and performant APIs, Go offers the perfect combination of simplicity, performance, and tooling to build modern backend services. This book is centered around a complete, real-world REST API project and guides you through every stage of the development process, from building HTTP handlers to applying authentication and generating OpenAPI documentation. You’ll learn to structure your application, handle persistence with common libraries like GORM and Squirrel, apply observability patterns through logging and tracing, and ensure code quality through unit and integration tests. Each concept is grounded in REST theory and backed by idiomatic Go practices, enabling you to build APIs that are not only functional but production-ready. By the end of the book, you’ll be ready to design, build, and maintain REST APIs in Go.
Table of Contents (18 chapters)
close
close
16
Other Books You May Enjoy
17
Index

Middleware

A middleware is a function executed before and/or after the handler, allowing you to do everyday tasks such as logging, authentication, authorization, and so on. The approach we will follow to build middleware in Go is to wrap our handler function with another function. This approach is known in other languages as the decorator pattern. I think it is going to be easier to understand with an example.

Let’s say that I want to log every request that is made to my API before it is done, and after it is done, I could do something like this:

func logRequest(next http.HandlerFunc) http.HandlerFunc {
  return func(w http.ResponseWriter, r *http.Request) {
    log.Printf("Before %s %s %s", r.Method, r.URL.Path, r.RemoteAddr)
    next(w, r)
    log.Printf("After %s %s %s", r.Method, r.URL.Path, r.RemoteAddr)
  }
}

As you can see here, a middleware is a function that receives a handler function and returns a new handler function, which is the...

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Modern REST API Development in Go
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon