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.
Length2 days. Each day is 4 hours long including a 15 minute break.
Class Size10 - 25 students. Need a larger or smaller class, just contact us for a custom quote.
- You have been doing daily Go development for 1-3 months.
- You want to learn how to create Web API's in Go
- 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.
- 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.
- 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
- Testing, Stubbing, and Automating Go Work Environments
- gRPC & gRPC Gateway Development in Go
- Advanced Go Development
- Profiling and Optimization in Go
- Students will learn about the structures in the standard library needed to create Web API's.
- Students will be able to create robust API's in Go.
- 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.
This module 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.
Understanding how Go web applications work means understanding the HTTP.Handler interface. This module will cover how
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.
Routing And Muxing
Routing in Go requires the use of a "muxer". In this module, we'll explore how to properly set up a muxer to route traffic properly in your web application.
This module will cover HTML templating with the standard library as well as other popular libraries.
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 module will go beyond the basics, and introduce concepts for production ready, well behaved, web application and services. This module 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.
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 module, we will cover both styles of testing and how to use them.
This chapter covers where to get more support on Go, recommends books and videos, and list the contact information for our instructors.
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:
- Error vs. Fatal
- Failure Messages
- 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 module we will cover the different ways to create, run, and isolate table driven tests.
Interfaces in Go provide a way to specify the behavior of an object:
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
pointer receivers and how they affect the ability to satisfy an
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
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.
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.