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

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.

主站蜘蛛池模板: 凤阳县| 株洲县| 秦皇岛市| 连江县| 大埔县| 迭部县| 特克斯县| 龙游县| 大渡口区| 应用必备| 即墨市| 壤塘县| 商丘市| 汉寿县| 阿坝县| 宜君县| 和顺县| 锡林郭勒盟| 冷水江市| 彭水| 维西| 华池县| 宜良县| 太白县| 桑植县| 浦城县| 六安市| 涿鹿县| 邹平县| 汤阴县| 江都市| 齐齐哈尔市| 齐齐哈尔市| 襄城县| 汉川市| 图们市| 广南县| 松江区| 边坝县| 乌拉特中旗| 民和|