Web API in Go Training

This course was designed for anyone wanting to learn how to use the standard library to create robust, effective, and performant Web API's in Go. Students will first learn about the constructs in the standard library that enable creating handlers, and how to use that knowledge to create custom API's. They will continue to use that knowledge to build on as they create custom routers, deal with validating and responding to error conditions from user input, and finish with learning how to write unit and integration tests for their API's.

Length

2 days. Each day is 4 hours long including a 15 minute break.

Class Size

Our classes are priced for small and large classes. We offer classes starting at only five students, up to 100 students. We recognize that each company has specific needs and budgets.

For pricing, fill out our contact us form and you'll receive an automated reply with our current rates.

Target Audience

  • You have been doing daily Go development for 1-3 months.
  • You want to learn how to create Web API's in Go
  • You want to understand Go's HTTP handling capabilities
  • You are building web APIs that require complex routing
  • You want to understand multiplexing and HTTP request handling in Go
  • You want to implement custom routing solutions
  • You are transitioning to building web services in Go

Prerequisites

  • Familiarity and comfort navigating and basic file manipulation at the command line.
  • Familiarity and comfort with a modern code editor, including creating and modifying files and projects.
  • You have 1 to 3 months of daily Go experience.
  • You have at least 6 months of experience with other modern development languages such as Java, C#, Swift, JavaScript, Python, Rust, etc.
  • Familiarity with basic programming concepts and structures such as variables, loops, conditionals, etc.
  • Computers should be capable of modern software development, such as access to install and run binaries, install a code editor, etc. Full instructions referenced here: preparing your environment for Go development. It may be necessary for them to have root/admin access to their computer.

Recommended Preparation

  • Install and configure an editor for Go.
  • Have a functioning Go environment installed with Go 1.13 or later.
  • Sign up for a Github account if you don't already have one.

Suggested Followup Learning

Expected Outcomes

  • Students will learn about the structures in the standard library needed to create Web API's.
  • Students will be able to explain and implement Go's http.Handler interface for handling web requests
  • Students will be able to create custom HTTP handlers to process different API endpoints and route types
  • Students will learn to design and implement middleware patterns to handle logging, authentication, and other cross-cutting concerns
  • Students will develop production-quality web services with comprehensive error handling and status codes
  • Students will demonstrate the ability to structure web applications using maintainable patterns and best practices for Go services
  • Students will understand and implement Go's built-in ServeMux for basic HTTP routing
  • Students will learn to create and mount multiple muxers for organizing route hierarchies
  • Students will build custom muxers to handle specific routing requirements like HTTP method-based routing
  • Students will evaluate the limitations of built-in muxing and understand when to use third-party routers
  • Students will implement path stripping and prefix handling for nested route structures
  • Students will understand the proper patterns needed to create testable, reusable code for Web API's in Go.
  • Students will learn how to deal with JSON as well as create custom JSON implementations.
  • Students will learn how to create unit tests and integration tests for web API's.

Course Details

Day One

Welcome

This chapter covers general information about your instructor and course materials.

Introduction To Go Web Development

This chapter will cover some basic concepts of web development in Go. We'll cover how to create handlers, set up routing, and launch a basic web server.

HTTP Handlers

Understanding how Go web applications work means understanding the HTTP.Handler interface. This chapter will cover how Handler, HandlerFunc and ServeHTTP all work together to create the basic building blocks of a Go web service. We will also cover how to create and implement middleware, such as a basic logger and authentication.

Break

Tea/Coffee Break.

Routing And Muxing

Routing in Go requires the use of a "muxer". In this chapter, we'll explore how to properly set up a muxer to route traffic properly in your web application.

HTML Templates

This chapter will cover HTML templating with the standard library as well as other popular libraries.

Day Two

Encoding JSON

Working with JSON in Go can present many challenges. This chapter will cover basic encoding/decoding, how to handle JSON that isn't consistent, as well as mapping JSON to structs.

Production Ready Web Services

This chapter will go beyond the basics, and introduce concepts for production ready, well behaved, web application and services. This chapter will talk about how to secure your service, introduce middleware and tracing, as well as show how to organize your code so that testing, mocking, and injection are easily accomplished.

Break

Tea/Coffee Break.

Testing Net/HTTP

In the standard library there are two mechanisms for us to use to test web applications.

  • Unit Style Testing
  • Integration Style Testing

These are not their "official" names, but we believe they do a good job of describing the styles of testing. In this chapter, we will cover both styles of testing and how to use them.

Finalize

This chapter covers where to get more support on Go, recommends books and videos, and list the contact information for our instructors.

Prerequisites

Testing Basics

Testing in Go is easy, and simple to use. There is a strong emphasis on testing in Go. The compiler will catch a lot of bugs for you, but it can not ensure your business logic is sound or bug-free.

While the testing package isn't large, there are some features that are not properly understood. In this chapter we will cover the following concepts:

  • *testing.T
  • Error vs. Fatal
  • Failure Messages
  • Helpers
  • Testing Packages

Table Driven Testing

Table driven tests can be used to cover a lot of ground quickly while re-using common setup and comparison code. Table driven testing is not unique to Go, however, it is very powerful. In this chapter we will cover the different ways to create, run, and isolate table driven tests.

Interfaces

Interfaces in Go provide a way to specify the behavior of an object: If something can do this, then it can be used here. This chapter will take a look at how to use interfaces to abstract that behavior. Concepts such as the Empty Interface, satisfying multiple interfaces, and asserting for behavior will be covered. Additionally, this chapter will cover the difference between value and pointer receivers and how they affect the ability to satisfy an interface.

Embedding And Composition

Go does not provide the typical type-driven notion of subclassing. However, it does have the ability to “borrow” pieces of an implementation by embedding types within a struct or interface. This chapter will cover how promotion from embedding works as well how collision and overriding are handled. We will also walk through how to embed types to be able to satisfy a specific interface.

Errors

Error handling in Go can feel a bit tedious at first. However, this chapter will cover the benefits of how Go's error model results in more reliable code. This chapter will also cover how to handle basic errors and return errors as an interface that satisfies the error type. Concepts such as custom error types, panics, recovering from panics, and sentinel errors are also covered.