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

Understanding httprouter – a lightweight HTTP router

 httprouter, as the name suggests, routes the HTTP requests to particular handlers. httprouter is a well-known package in Go for creating simple routers with an elegant API. The developers coming from the Python/Django community are very familiar with a full-blown URL dispatcher in the Django framework. httprouter provides similar features:

  • Allows variables in the route paths
  • Matches the REST methods (GET, POST, PUT, and so on)
  • No compromise of performance

We are going to discuss these qualities in more detail in the following section. Before that, there are a few noteworthy points that make httprouter an even better URL router:

  • httprouter plays well with the in-built http.Handler
  • httprouter explicitly says that a request can only match to one route or no route
  • The router's design encourages building sensible, hierarchical RESTful APIs
  •  You can build simple and efficient static file servers

In the next section, we see the installation of httprouter and its basic usage.

主站蜘蛛池模板: 绍兴市| 饶平县| 澄迈县| 明水县| 龙川县| 响水县| 云霄县| 古田县| 长岭县| 保德县| 陕西省| 宝应县| 喜德县| 长春市| 济南市| 宣汉县| 始兴县| 东阳市| 武邑县| 牟定县| 开鲁县| 林周县| 井研县| 皮山县| 西华县| 色达县| 岳西县| 浪卡子县| 元谋县| 澄江县| 永德县| 东阿县| 金溪县| 六盘水市| 锡林浩特市| 神农架林区| 涞水县| 金坛市| 谢通门县| 元氏县| 湟中县|