官术网_书友最值得收藏!

Handling Routing for Our REST Services

In this chapter, we will discuss routing of the application. For creating an API, the first step is to define routes. So, to define routes, we need to figure out available constructs in Go. We begin with the basic internal routing mechanism in Go. Then, we see how to create a custom Multiplexer. Since ServeMux's capabilities are very limited, we will explore a few other frameworks built to serve this purpose. This chapter also includes creating routes using third-party libraries such as httprouter and Gorilla Mux. We are going to build a URL-shortening API throughout this book. In this chapter, we define routes for the API. Then, we discuss topics like SQL injection of an URL. A web framework allows the developer to create a route as the first step and then attach handlers to it. Those handlers hold the business logic of the application. The crux of this chapter is teaching you how to create HTTP routers in Go using Gorilla Mux. We also discuss how URL-shortening service functions and try to design a logical implementation.

We will cover the following topics:

  • Building a basic web server in Go
  • Understanding the net/http package
  • ServeMux, a basic router in Go
  • Understanding httprouter, a router package
  • Introducing Gorilla Mux, a powerful HTTP router
  • Introducing URL shortening service design 
主站蜘蛛池模板: 英吉沙县| 宝清县| 深泽县| 莆田市| 寻乌县| 翁源县| 万全县| 拉萨市| 石阡县| 肇源县| 通城县| 纳雍县| 恭城| 偏关县| 潍坊市| 安化县| 郧西县| 绵竹市| 承德县| 阿勒泰市| 青铜峡市| 浮山县| 庆城县| 正安县| 唐海县| 庆云县| 若尔盖县| 贡山| 永顺县| 岳普湖县| 巫山县| 永昌县| 株洲市| 安福县| 聊城市| 分宜县| 汕尾市| 柳江县| 永登县| 舞阳县| 奉贤区|