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

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.

主站蜘蛛池模板: 麻阳| 平乡县| 离岛区| 化州市| 柞水县| 乡宁县| 固阳县| 丹东市| 襄垣县| 石景山区| 班戈县| 赫章县| 罗田县| 改则县| 广汉市| 聊城市| 沧州市| 苍溪县| 财经| 岑溪市| 内乡县| 新绛县| 临沧市| 都昌县| 刚察县| 崇义县| 拉萨市| 塘沽区| 涪陵区| 黔南| 中方县| 通江县| 称多县| 乌兰县| 黄大仙区| 临江市| 哈尔滨市| 鹤山市| 榆中县| 刚察县| 潮州市|