We may earn an affiliate commission when you visit our partners.
Packt Publishing

REST is an architectural style that tackles the challenges of building scalable web services. APIs provide the fabric through which systems interact, and REST has become synonymous with APIs. The depth, breadth, and ease of use of Go, make it a breeze for developers to work with it to build robust Web APIs. This course will teach you to build a RESTful web server. You will learn to add routing and handle requests, thus making your APIs more RESTful. Later, by testing and profiling your code you will ensure it runs correctly and behaves well at scale. Moving on with security, you will learn to log requests and outcomes of API calls and speed up performance using the Echo framework. By the end of this course, you will have the knowledge you need to start building your own enterprise-grade RESTful web services that are production-ready, secure, scalable, and reliable.

Read more

REST is an architectural style that tackles the challenges of building scalable web services. APIs provide the fabric through which systems interact, and REST has become synonymous with APIs. The depth, breadth, and ease of use of Go, make it a breeze for developers to work with it to build robust Web APIs. This course will teach you to build a RESTful web server. You will learn to add routing and handle requests, thus making your APIs more RESTful. Later, by testing and profiling your code you will ensure it runs correctly and behaves well at scale. Moving on with security, you will learn to log requests and outcomes of API calls and speed up performance using the Echo framework. By the end of this course, you will have the knowledge you need to start building your own enterprise-grade RESTful web services that are production-ready, secure, scalable, and reliable.

About the Author

Bartlomiej Walczak has almost two decades of web development and security experience. He wrote front-ends and back-ends at various scales in PHP, Python, Node.js, and Go. He has worked for large clients and small startups, learning the value of structure from the former, and agility from the latter. These days, Go remains his language of choice; he prefers it due to its ease of use, extensive testing framework, and powerful multithreading capabilities.

Enroll now

Here's a deal for you

We found an offer that may be relevant to this course.
Save money when you learn. All coupon codes, vouchers, and discounts are applied automatically unless otherwise noted.

What's inside

Learning objectives

  • Build and test robust restful apis using go.
  • Integrate modern databases with your web services
  • Secure access to your api with auth and traffic with json web encryption.
  • Test and profile your code.
  • Track the proper execution of your code with logs.
  • Creating a client library for your api that other developers can consume.
  • Select and use modern api frameworks such as echo.

Syllabus

RESTful API in Go - Why?

This video explains the course prerequisites and provides an entire overview of the course.

Go is supported by many tools out there. Let’s select the ones that will be useful for us in this course.

  • Install Go and check the installation

  • Choose an IDE

  • Install additional helper tools

Read more

Go is a relatively new language. We will understand why it is particularly well suited to write RESTful APIs.

  • Understand the convenience of using the Go language

To have a working API we need a working web server.

  • Create a web server

  • Start and test the server

  • Understand error handling in Go

Any API needs to handle various routes and requests.

  • Learn where to get detailed help

  • Understand the HandleFunc type

  • Create the default route

Each route needs a handler to work correctly.

  • Create the handler function

  • Write header and output

  • Test the default route

Invalid request should produce an error with the appropriate status code.

  • Check if the request URL is correct

  • Output the error message and code

  • Test valid and invalid requests

Using curl to test API is cumbersome. Postman is an industry standard when it comes to organized API testing.

  • Create a collection

  • Create a request

  • Test the request

Every API needs a specification that describes what the functionality should be.

  • Establish basic premises

  • Define each request

  • Define typical responses

API data must persist in the event of server failure.

  • Select a permanent data store solution

  • Install required tools and libraries

  • Create a data structure

Stored data needs to be read and modified.

  • Establish data store location

  • Add data manipulation functions

  • Add data validation

Default router in Go doesn’t parse request methods and doesn’t understand URI parameters. For an API it’s vital that each method is handled differently and that parameters are properly parsed.

  • Create a handler function for a given resource

  • Add routing for collection

  • Add routing for an item

GET request to a resource collection should produce a list of items.

  • Create a generic response function

  • Write the request handler

  • Test the added route

POST request to resource collection should create a new item in the collection from the request body.

  • Understand POST, PUT and PATCH requests

  • Create a function to parse body content

  • Write and test POST request handler

GET request to a collection item should produce this item’s data. It’s also possible to streamline our testing using Postman’s additional capabilities.

  • Write and test GET request handler

  • Learn about Postman environments and variables

  • Save last inserted id into a Postman variable

PUT request to a collection item should replace the item’s current data with request body.

  • Write the request

  • Hook the request in the router

  • Test the request in Postman

PATCH request to a collection item should update the item’s current data with request body.

  • Write the request

  • Hook the request in the router

  • Test the request in Postman

DELETE request to a collection item should remove the item record from the collection.

  • Write the request

  • Test the request in Postman

  • Remove the last inserted id Postman variable

HEAD request to a resource should mirror GET request path but only output the header.

  • Learn about the use cases for HEAD request

  • Modify the GET request handlers

  • Test the requests in Postman

OPTIONS request should return a list of valid methods that a given resource accepts. It can also be used to document the API.

  • Create a generic OPTIONS response function

  • Hook the requests in the router

  • Test the requests in Postman

Tests should be an integral part of development. Bug-ridden code is not worth anything.

  • Understand the difference between various test types

  • Understand what makes a good test

  • Learn how unit tests are implemented in Go

Not all tests are created equal. Good ones cover all functionality and most of the test cases.

  • Understand the concept of a test suite

  • Write unit tests covering invalid cases

  • Write unit tests covering all valid cases

A decent test is better than no test at all. Learn how to write tests that are still meaningful, despite not being comprehensive.

  • Understand when a test is “good enough”

  • Write a minimum viable unit test

  • Learn about test setup and cleanup

Good code is good, but good and fast code is better. How to determine which code is slow?

  • Learn about benchmark implementation in Go

  • Write and run CRUD benchmarks

  • Write and run a separate benchmark for each operation

Caching is the best way to reduce execution time of your most common requests and should be the first API optimization.

  • Selecting solutions and specifying cache implementation

  • Creating cache structure and functions

  • Adding cache to request handlers

How do we make sure that we cache exactly what is being sent out?

  • Learn about interfaces in Go

  • Create a custom ResponseWriter

  • Inject the custom writer in the response chain

Some functionality depends on operations such as disk or network access that introduce considerable lag and uncertainty. How to test it reliably?

  • Learn about mock-ups

  • Create a ResponseWriter mock-up

  • Write unit tests for our cache Writer

When performing code optimization, it is important to measure the impact of the updated code. Sometimes the results might not be what you expect.

  • Prepare the database for benchmarks

  • Write benchmark tests for cached requests

  • Run benchmarks and compare the results

Frameworks are third-party code that can give you a significant head start when developing common features.

  • Learn the pros and cons of using frameworks

  • Learn about various Go frameworks

  • Explore gzip compression option

Echo is an extremely fast, extensible framework. We’re going to learn how to use it.

  • Start a web server in Echo

  • Write a root route handler

  • Test default functionality

How would our API look like when written in Echo? Let’s find out.

  • Add routes

  • Add route handlers

  • Test functionality in Postman using new environment

Important functionality is added to APIs via various types of middleware. You need to know your options.

  • Learn about middleware

  • Add simple middleware with default configuration

  • Write custom middleware and add configured middleware

This video summarizes the course and gives suggestions on further learning.

Traffic lights

Read about what's good
what should give you pause
and possible dealbreakers
Uses Go, which is known for its ease of use, extensive testing framework, and powerful multithreading capabilities, making it suitable for building robust web APIs
Covers testing and profiling, which ensures code runs correctly and behaves well at scale, contributing to the development of reliable and scalable APIs
Explores the Echo framework, which can speed up performance and simplify API development, offering practical skills for building efficient web services
Teaches how to create a client library for the API, which enables other developers to easily consume and integrate with the API, promoting wider adoption
Requires installing Go and additional helper tools, which may require some initial setup and configuration, but are essential for following along with the course
Relies on Postman for API testing, which requires learners to download and familiarize themselves with this third-party tool, potentially adding a learning curve

Save this course

Create your own learning path. Save this course to your list so you can find it easily later.
Save

Reviews summary

Building robust restful apis in go

According to students, this course provides a solid foundation in building RESTful APIs using Go. Learners particularly praise the clear explanations and practical, hands-on approach with useful code examples. The course covers essential topics like routing, testing, and introducing the Echo framework. While many find the content valuable for understanding core concepts and getting started, some suggest that parts might need updating for current dependencies and that prior basic Go knowledge is beneficial. Overall, it's seen as a highly positive starting point for developers looking to build web services with Go.
Provides a useful introduction to the Echo framework.
"Getting introduced to the Echo framework was very valuable."
"Learning how to use Echo simplified a lot of the API development process."
"The section on Echo helped me see how frameworks can speed things up."
Covers essential aspects of building APIs thoroughly.
"It covered the fundamental building blocks of RESTful APIs in Go very well."
"Topics like routing, handling requests, and basic security were explained effectively."
"I feel like I have a good grasp of the core principles needed to start building."
Instructor explains concepts clearly and effectively.
"The instructor explains concepts very clearly and uses good examples."
"I really appreciated how the lecturer broke down complex topics into understandable parts."
"The way the material is presented makes it easy to follow along, even with new ideas."
Excellent course for beginners to Go API development.
"This course is an excellent starting point for anyone wanting to build APIs in Go."
"It gave me the confidence to start my own Go API projects."
"If you're new to Go web development, this is a great place to begin."
Focus on practical coding and real-world examples.
"The course is very hands-on, with lots of coding examples that are easy to follow."
"I learned by doing, thanks to the practical exercises and projects provided."
"The code examples were directly applicable and helped solidify my understanding of building APIs."
Some library versions might require updates.
"A few of the dependencies used in the course code seem a bit outdated."
"Needed to spend some time updating libraries to get the examples working smoothly."
"It would be great if the code examples were updated to the latest Go practices and libraries."
May require prior basic understanding of Go.
"While the course is good, it seems to assume you already know the basics of Go."
"Beginners to Go might find the pace challenging at times."
"I recommend having some familiarity with Go syntax and concepts before starting."

Activities

Be better prepared before your course. Deepen your understanding during and after it. Supplement your coursework and achieve mastery of the topics covered in Building RESTful APIs with Go with these activities:
Review HTTP Methods
Solidify your understanding of HTTP methods (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS) before diving into building RESTful APIs. Knowing when and how to use each method is crucial for designing a RESTful interface.
Browse courses on HTTP Methods
Show steps
  • Read articles about HTTP methods.
  • Study examples of RESTful API design.
  • Take a quiz on HTTP methods.
Read "RESTful Web APIs" by Leonard Richardson
Gain a deeper understanding of RESTful principles and best practices by reading this book. It will provide a solid foundation for building well-designed APIs with Go.
Show steps
  • Read the book cover to cover.
  • Take notes on key concepts.
  • Try implementing the examples in Go.
Build a Simple CRUD API
Practice building a basic CRUD (Create, Read, Update, Delete) API using Go. This hands-on project will reinforce your understanding of routing, request handling, and data persistence.
Show steps
  • Define the API endpoints.
  • Implement the handlers for each endpoint.
  • Connect to a database (e.g., SQLite, PostgreSQL).
  • Test the API using Postman or curl.
Four other activities
Expand to see all activities and additional details
Show all seven activities
Implement API Authentication
Practice implementing different authentication methods (e.g., Basic Auth, API Keys, JWT) in your Go API. This will help you understand how to secure your APIs and protect sensitive data.
Show steps
  • Choose an authentication method.
  • Implement the authentication logic.
  • Test the authentication using Postman.
Read "Go Web Programming" by Sau Sheong Chang
Expand your knowledge of Go web development by reading this book. It will provide practical examples and insights into building robust web applications, including RESTful APIs.
Show steps
  • Read the book cover to cover.
  • Try the code examples.
  • Apply the concepts to your own projects.
Write a Blog Post on API Design
Solidify your understanding of API design principles by writing a blog post explaining key concepts and best practices. This will force you to organize your thoughts and communicate your knowledge effectively.
Show steps
  • Choose a specific API design topic.
  • Research the topic thoroughly.
  • Write a clear and concise blog post.
  • Include code examples and diagrams.
Contribute to a Go API Library
Contribute to an open-source Go library related to API development. This will give you valuable experience working on a real-world project and collaborating with other developers.
Show steps
  • Find a suitable open-source project.
  • Identify an issue to work on.
  • Submit a pull request with your changes.

Career center

Learners who complete Building RESTful APIs with Go will develop knowledge and skills that may be useful to these careers:
API Developer
An API Developer specializes in designing, developing, and managing Application Programming Interfaces that allow different software systems to communicate with each other. This role requires a strong understanding of architectural styles like REST. This course is a perfect fit for any aspiring API developer, as it teaches how to construct RESTful APIs using Go. By focusing on handling requests, implementing routing, testing and profiling, and securing APIs, this course covers the fundamental skills necessary for an API developer to create an API that is both functional and scalable. The course also shows you how to integrate databases and use modern frameworks to make APIs more robust.
Backend Developer
A Backend Developer is primarily responsible for building and maintaining the server-side logic of web applications. This involves designing APIs, managing databases, and ensuring that the system functions efficiently for all users. Taking a course like this would help a backend developer learn to design and build RESTful web services using Go. The course’s focus on building a robust RESTful web server, handling requests, and implementing security features is directly relevant to the responsibilities of a backend developer, who would also benefit from the training in testing, profiling, and using frameworks like Echo to optimize performance and provide reliable service.
Web Services Developer
A Web Services Developer is responsible for creating and maintaining web services that enable communication between different applications and systems. A web services developer must be proficient in building and deploying APIs. With this course, a web services developer builds a foundation in the design of RESTful web services using Go, enabling them to build scalable and reliable applications. The course’s emphasis on routing, request handling, and data persistence will be key in the day-to-day work of a web services developer. Further, this course teaches how to test, profile, and secure web services to ensure functionality, performance, and safety.
Software Engineer
A Software Engineer is responsible for the full software development lifecycle, including design, implementation, and maintenance. A software engineer who wishes to work with web services would find this course beneficial. The course’s focus on building RESTful APIs with Go, including handling requests, managing data, and security, provides a strong foundation for creating scalable and reliable web services. Working through the course's practical exercises, a software engineer gains valuable experience in testing, profiling, using modern frameworks, and integrating databases, which are essential for a well-rounded software engineer.
Cloud Engineer
A Cloud Engineer specializes in designing, building, and maintaining cloud computing infrastructure and services. Their responsibilities include deploying applications, managing cloud resources, and ensuring the security and scalability of cloud systems. This course is beneficial for a cloud engineer, as it provides the skills to build robust and scalable web APIs using Go, which are essential for cloud-based services. The course’s focus on RESTful architecture, request handling, and performance optimization is directly applicable. Additionally, the training in database integration, security, and frameworks like Echo, will equip cloud engineers with the knowledge required to deploy and manage cloud-based applications effectively.
Systems Architect
A Systems Architect designs and oversees the development of complex systems, ensuring they meet performance, reliability, and scalability requirements. This role requires a broad understanding of system architecture, API design, and various development technologies. This course may be useful for a systems architect, as it focuses on building RESTful APIs with Go that are production-ready, secure, scalable, and reliable. The course offers insight into request handling, routing, data persistence, testing, and profiling. Although a systems architect will not be primarily writing code, this course provides a foundation in modern API design.
DevOps Engineer
A DevOps Engineer is responsible for bridging the gap between development and operations, automating software delivery, and ensuring the reliability of systems. This role has many responsibilities, including the deployment and maintenance of APIs. This course may be useful for a DevOps Engineer, as it teaches the skills needed to build and test robust RESTful APIs with Go, including database integration and secure access. The course also covers automated testing, performance profiling, and logging, which are all important skills for DevOps professionals. Though not a core skill, knowledge of API development helps DevOps engineers understand underlying architecture.
Solutions Architect
A Solutions Architect designs and oversees the implementation of technical solutions, aligning business needs with technology. This role requires an understanding of various systems, including APIs and backend infrastructure. This course may help a solutions architect build a deeper understanding of the underlying architecture of modern APIs. The course's focus on RESTful APIs with Go, including request handling, routing, security, and database integration, can help the architect with system design. Although not directly coding, a solutions architect would benefit from this deeper understanding of API development.
Technical Lead
A Technical Lead provides technical guidance and direction to development teams, ensuring projects are executed effectively and efficiently. They typically have a strong technical background that allows them to manage complex projects. This course may be helpful to a technical lead, as it provides a practical understanding of building RESTful web services with Go. The course’s coverage of API design, routing, request handling, data persistence, testing, and profiling, along with an understanding of the Echo framework, provides a foundation that is vital for a technical lead, who is responsible for overseeing a project's successful execution.
Application Developer
An Application Developer is responsible for designing, coding, and testing software applications. They may work on frontend or backend development. A course like this may be useful for any application developer, especially those working on the back end. The course focuses on building RESTful APIs using Go, including request handling, routing, and database integration. This directly contributes to the skills needed for developing robust and scalable applications. Furthermore, the course on testing, profiling, security, and use of the Echo framework, is beneficial for any application developer looking to build and maintain modern web services.
Integration Engineer
An Integration Engineer specializes in connecting different software systems and ensuring they work together seamlessly. They work with data formats, APIs, and protocols to enable integration. This course may be helpful for an Integration Engineer, as it covers the creation of RESTful web services using the Go programming language. The course focuses on how to handle requests, manage routing, use databases, and ensure that APIs are secure. An integration engineer would also benefit from the training in testing, profiling, and the use of frameworks such as Echo, which helps speed up performance.
Data Engineer
A Data Engineer develops, maintains, and tests infrastructures for data generation and storage, which may include data warehouses and pipelines. These types of data projects often use APIs to connect to data sources. This course may be helpful for a data engineer, as it covers building robust and scalable RESTful APIs using Go. The course includes information about integrating databases with web services, making it beneficial for data infrastructure projects. In addition, the course teaches testing, profiling, and securing APIs, which helps to build reliable data systems.
Technical Consultant
A Technical Consultant provides expert advice and guidance on technology solutions. They may require a broad understanding of software development and architecture. This course may be helpful for a technical consultant as it provides an overview of RESTful API development using Go. The skills taught include building web servers, handling requests, and securing APIs. Though they do not directly code on a daily basis, technical consultants would benefit from the coverage of testing, profiling, and the use of frameworks, as this allows them to provide informed recommendations to clients.
Site Reliability Engineer
A Site Reliability Engineer focuses on ensuring that systems are reliable and performant. This role requires a strong understanding of system internals, monitoring, and automation. This course may be helpful for a site reliability engineer, as it covers the creation of robust RESTful APIs using Go. The course touches on testing, profiling and security, as well as frameworks that are critical to building reliable web services. SREs are often involved in the testing and deployment of code, and would benefit from understanding the specific concerns of API development, but this is not core to the role.
Database Administrator
A Database Administrator is responsible for the performance, integrity, and security of an organization's databases. This includes tasks such as setup, maintenance, and backups. This course may be useful for a database administrator who will work on databases that are connected to APIs because the course teaches how to integrate databases with web services. The course also includes information on how to secure access to an API, which would also be useful. However, a database administrator does not deal directly with API code, making this less of a core skill.

Reading list

We've selected two books that we think will supplement your learning. Use these to develop background knowledge, enrich your coursework, and gain a deeper understanding of the topics covered in Building RESTful APIs with Go.
Provides a comprehensive guide to designing and building RESTful web APIs. It covers the principles of REST, how to apply them in practice, and how to use HTTP effectively. It valuable resource for understanding the architectural style behind RESTful APIs. This book is commonly used as a reference by industry professionals.
Provides a practical guide to building web applications with Go, including RESTful APIs. It covers topics such as routing, templating, data persistence, and security. It useful resource for learning how to apply Go to web development. This book is more valuable as additional reading than it is as a current reference.

Share

Help others find this course page by sharing it with your friends and followers:

Similar courses

Similar courses are unavailable at this time. Please try again later.
Our mission

OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.

Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.

Find this site helpful? Tell a friend about us.

Affiliate disclosure

We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.

Your purchases help us maintain our catalog and keep our servers humming without ads.

Thank you for supporting OpenCourser.

© 2016 - 2025 OpenCourser