gRPC & gRPC Gateway development in Go Training
This course was designed for anyone wanting to learn gRPC and the gRPC Gateway. Students will learn how to use the Protocol Buffer language to define messages and services for gRPC. They will learn how to create synchronous and asynchronous endpoints (streaming and non-streaming) as well as how to configure and secure their services. They'll also learn how to configure their gRPC services to automatically generate and handle legacy RESTful JSON endpoints by using the gRPC Gateway.
Length
3 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 services with gRPC and Protocol Buffers in Go
- You need to support legacy RESTful JSON API's with your new services.
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
- Testing, Stubbing, and Automating Go Work Environments
- Web API Development in Go
- Advanced Go Development
- Profiling and Optimization in Go
Expected Outcomes
- Students will learn the Protocol Buffer syntax and how to create messages and services with Proto syntax.
- Students will be able to generate robust services with gRPC in Go.
- Students will learn how to create gRPC streams for accepting multiple messages in a service request.
- Students will learn how to secure and configure their gRPC services.
- Students will learn how to create unit tests and integration tests for gRPC services.
- Students will be able to configure their projects to create RESTful JSON endpoints for existing services with the gRPC Gateway Project.
Course Details
Day One
Install And Configure Protobuf
Installing all the tools you need to make protocol buffers work can be challenging. This chapter lays out in detail the steps needed to properly install and configure your development environment for protocol buffers. It also includes specific steps for each operating system when necessary.
Protocol Buffers
Protocol Buffers are the next step in data formats for high performance distributed systems. In comparison to JSON or XML, protobufs can encode and decode faster, have a smaller encoded size, and allow for use across platforms and languages. In this chapter, we will cover how to create and use protocol buffers, as well as how to extend them.
Break
Tea/Coffee Break.
Introduction To GRPC
gRPC is a modern open source high performance RPC framework that can run in any environment. In this chapter we will cover the basic concepts used in gRPC, as well as create some simple RPC calls using protocol buffers and implement them with gRPC. We'll also cover how to create specific errors and codes with gRPC.
Streaming With GPRC
Streaming in gRPC allows for the client or server to send and receive more than one message. This allows for asynchronous processing and bi-directional communication. This module will cover client streaming, server streaming, and bi-directional streaming.
Day Two
GRPC Metadata
Similar to how HTTP protocol can send headers, gRPC allows you to send key/value pairs via metadata. This module shows how to set and retrieve metadata, and guidelines around when to use it.
Observing SLA's With GRPC
Service Level Agreements (SLA's) are an important part of your API. This chapter will discuss how to implement them on the client and server, and best practices to follow. Contexts are the mechanism that is used to control SLA's in the gRPC ecosystem. As such, we'll also cover additional characteristics of how context works with gRPC beyond SLA's.
Break
Tea/Coffee Break.
Securing GRPC Services
gRPC provides a simple authentication API based around the unified concept of Credentials objects, which can be used when creating an entire gRPC channel or an individual call. Credentials can be of two types: Channel credentials, which are attached to a Channel, such as SSL credentials. Call credentials, which are attached to a call. This chapter will cover how to secure a channel and how to secure a call.
Testing And Stubbing GRPC
This chapter will show how to approach testing for both client and server services. We will also cover how to stub out specific parts of the stack to enable easy unit testing.
GRPC Middleware
Middleware is a common way to handle many concepts such as logging, tracing, and more. You can implement middleware in your gRPC stack with "interceptors". This chapter will show how to create basic interceptors and cover existing third party interceptors, as well as setting up retry logic, and load balancing.
Day Three
GRPC Telemetry
gRPC Telemetry consists of two pieces: metrics and traces. This chapter will cover how to enable modern observability in your distributed gRPC applications using OpenTelemetry, the industry-standard unified observability framework.
gRPC Tooling
This chapter will cover many useful tools for working with a gRPC API. You will learn how to use common "curl" tools to interact with your API, set up load testing, run a protobuf linter, and more.
Break
Tea/Coffee Break.
gRPC Gateway
The grpc-gateway is a plugin of the Google protocol buffers compiler protoc. It reads protobuf service definitions and generates a reverse-proxy server which translates a RESTful HTTP API into gRPC. This chapter will cover how to specify the proper definitions in your proto files to generate the RESTful endpoints. It will also cover how to use OpenAPI to quickly test your endpoints.
Prerequisites
Introduction to Go Web Development: Building a Simple HTTP Server and Web Services
In this chapter, you will dive into the basics of web development using Go. You’ll learn how to build a simple web server, create HTTP handlers, and set up routing using Go’s powerful net/http package. Starting with a basic "Hello, World!" web application, we will guide you through key concepts such as routing, serving static files, handling headers, and securing your server with TLS. By the end of this chapter, you’ll have a solid foundation for developing web services in Go, complete with the ability to handle multiple routes and build reliable HTTP applications.
Advanced Routing and Muxing in Go: Building Robust Web Application Routes
This chapter dives deep into the implementation of routing and multiplexing for advanced web development in Go. It covers the basics of using Go’s built-in http.ServeMux for simple routing, along with the limitations of this default multiplexer. The chapter then transitions into constructing more complex routing setups, including: Using Multiple Muxers: Learn how to handle and mount multiple muxers, how path stripping works, and the importance of proper path handling. Custom Muxer Development: A step-by-step guide to building a custom muxer from scratch using Go’s http.Handler interface, illustrating how you can gain full control over your routing logic. Handling HTTP Methods (Verbs): Understand how to create routes that differentiate between HTTP methods such as GET, POST, and DELETE, and route requests accordingly. Limitations of http.ServeMux: Explore why the built-in mux might not be sufficient for production-level applications, leading to the use of third-party routers like
Building HTTP Handlers for Web Applications: Handling Routes, Processing Requests, and Sending Responses
In this chapter, we explore the fundamentals of building HTTP handlers in Go, which are the backbone of any web application. You will learn about the http.Handler interface, HandlerFunc, and how to implement them effectively to process requests and send responses. We’ll also delve into how middleware can extend your handlers by adding functionalities such as logging, authentication, and more. By the end of this chapter, you’ll be equipped to create robust and reusable HTTP handlers for your web services, complete with middleware for pre- and post-processing requests.
Testing Basics: Writing and Running Unit Tests
This chapter introduces the fundamentals of testing in Go, with a focus on writing and running unit tests using the built-in testing package. You'll learn how to structure tests, the importance of naming conventions, and how to utilize the *testing.T type to create effective test cases. Key concepts such as the difference between Error and Fatal, crafting meaningful failure messages, and organizing internal vs. external tests are explored. Additionally, we'll cover useful helper functions, alternative testing packages, and provide practical examples to help you develop reliable, maintainable tests for your Go applications.
Testing HTTP Handlers with Net/HTTP: Writing Tests for HTTP Services and Utilizing the net/http/httptest Package
In this chapter, we dive into testing HTTP handlers in Go, leveraging the net/http/httptest package. Testing HTTP handlers can be approached in two distinct styles: Unit Style Testing and Integration Style Testing. Each style serves different purposes in ensuring that your web applications work as expected. We will explore both approaches, demonstrating how to mock HTTP requests, simulate responses, and write efficient tests for your web services. Additionally, you'll learn how to create test servers, utilize middleware, and handle request bodies and form data. By the end of this module, you’ll have the skills to write comprehensive and reliable tests for Go-based web applications.