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

Handling Routing for our REST Services

In this chapter, we will discuss routing for a REST application. To create an API, the first step is to define routes. To define routes, we have to figure out the available system packages in Go. We'll begin this chapter by exploring the basic internal routing mechanism in Go. We then see how to create a custom multiplexer, an entity that matches a given URL to a registered pattern. A multiplexer basically allows a developer to create a route to listen to client requests and attaches handlers that hold the business logic of the application. The ServeMux package is the basic multiplexer provided by Go. We'll then explore a few other frameworks as ServeMux capabilities are very limited.

This chapter also includes the likes of third-party libraries such as httprouter and gorilla/mux. Then, we'll discuss topics such as SQL injection. The crux of this chapter is to teach you how to create elegant HTTP routers in Go using gorilla/mux. We'll also briefly discuss designing a URL shortening service.

We will cover the following topics:

  • Understanding Go's  net/http package
  • ServeMux—a basic router in Go
  • Understanding httprouter—a lightweight HTTP router
  • Introducing gorilla/mux—a powerful HTTP router
  • Reader's challenge: an API for URL shortening

主站蜘蛛池模板: 抚顺县| 乌兰察布市| 平武县| 凤台县| 禹城市| 泉州市| 镶黄旗| 出国| 霍林郭勒市| 上高县| 富锦市| 手游| 大荔县| 信阳市| 高尔夫| 南昌市| 黄石市| 兴城市| 南木林县| 湖北省| 错那县| 乐业县| 枣阳市| 东宁县| 寿光市| 曲靖市| 香河县| 永康市| 凌云县| 保山市| SHOW| 阿拉善盟| 衡阳市| 花垣县| 揭东县| 天柱县| 大关县| 沂南县| 资溪县| 克拉玛依市| 苗栗市|