A minimalist HTTP request routing helper for Go.

Overview

R2

GitHub Actions codecov Go Report Card PkgGoDev

A minimalist HTTP request routing helper for Go.

The name "R2" stands for "Request Routing". That's all, R2 is just a capable little helper for HTTP request routing, not another fancy web framework that wraps net/http.

R2 is built for people who:

  • Think net/http is powerful enough and easy to use.
  • Don't want to use any web framework that wraps net/http.
  • Don't want to use any variant of http.Handler.
  • Want http.ServeMux to have better performance and support path parameters.

Features

  • Extremely easy to use
  • Blazing fast (see benchmarks)
  • Based on radix tree
  • Sub-router support
  • Path parameter support
  • Path auto-correction support
  • No http.Handler variant
  • Middleware support
  • Zero third-party dependencies
  • 100% code coverage

Installation

Open your terminal and execute

$ go get github.com/aofei/r2

done.

The only requirement is the Go, at least v1.13.

Hello, 世界

Create a file named hello.go

package main

import (
	"fmt"
	"net/http"

	"github.com/aofei/r2"
)

func main() {
	r := &r2.Router{}
	r.Handle("", "/hello/:name", http.HandlerFunc(hello))
	http.ListenAndServe("localhost:8080", r)
}

func hello(rw http.ResponseWriter, req *http.Request) {
	fmt.Fprintf(rw, "Hello, %s\n", r2.PathParam(req, "name"))
}

and run it

$ go run hello.go

then visit http://localhost:8080/hello/世界.

Community

If you want to discuss R2, or ask questions about it, simply post questions or ideas here.

Contributing

If you want to help build R2, simply follow this to send pull requests here.

License

This project is licensed under the MIT License.

License can be found here.

You might also like...
A high performance fasthttp request router that scales well
A high performance fasthttp request router that scales well

FastHttpRouter FastHttpRouter is forked from httprouter which is a lightweight high performance HTTP request router (also called multiplexer or just m

Simple Golang HTTP router
Simple Golang HTTP router

Bellt Simple Golang HTTP router Bellt Package implements a request router with the aim of managing controller actions based on fixed and parameterized

Lightning Fast HTTP Multiplexer
Lightning Fast HTTP Multiplexer

bone What is bone ? Bone is a lightweight and lightning fast HTTP Multiplexer for Golang. It support : URL Parameters REGEX Parameters Wildcard routes

FastRouter is a fast, flexible HTTP router written in Go.

FastRouter FastRouter is a fast, flexible HTTP router written in Go. FastRouter contains some customizable options, such as TrailingSlashesPolicy, Pan

High-speed, flexible tree-based HTTP router for Go.

httptreemux High-speed, flexible, tree-based HTTP router for Go. This is inspired by Julien Schmidt's httprouter, in that it uses a patricia tree, but

:rotating_light: Is a lightweight, fast and extensible zero allocation HTTP router for Go used to create customizable frameworks.
:rotating_light: Is a lightweight, fast and extensible zero allocation HTTP router for Go used to create customizable frameworks.

LARS LARS is a fast radix-tree based, zero allocation, HTTP router for Go. view examples. If looking for a more pure Go solution, be sure to check out

A powerful HTTP router and URL matcher for building Go web servers with 🦍

gorilla/mux https://www.gorillatoolkit.org/pkg/mux Package gorilla/mux implements a request router and dispatcher for matching incoming requests to th

An extremely fast Go (golang) HTTP router that supports regular expression route matching. Comes with full support for building RESTful APIs.

ozzo-routing You may consider using go-rest-api to jumpstart your new RESTful applications with ozzo-routing. Description ozzo-routing is a Go package

Pure is a fast radix-tree based HTTP router
Pure is a fast radix-tree based HTTP router

package pure Pure is a fast radix-tree based HTTP router that sticks to the native implementations of Go's "net/http" package; in essence, keeping the

Owner
Aofei Sheng
Try to glue everything together.
Aofei Sheng
An HTTP request routing benchmark suite for Go.

Go HTTP Request Routing Benchmark An HTTP request routing benchmark suite for Go. Results goos: linux goarch: amd64 pkg: github.com/aofei/go-http-requ

Aofei Sheng 5 Dec 14, 2021
Bxog is a simple and fast HTTP router for Go (HTTP request multiplexer).

Bxog is a simple and fast HTTP router for Go (HTTP request multiplexer). Usage An example of using the multiplexer: package main import ( "io" "net

Eduard 103 Sep 7, 2022
simulate linkstate algorithm for routing

for final project of computer-network course in SBU university (spring 2021) we implemented a Link-state simulation in go.

Roozbeh Sharifnasab 6 Sep 20, 2022
Vehicle Routing Problem Solver in Go

VehicleRoutingProblem Vehicle routing problem heuristic in Go Tests To run the test simply go with go test -v ./... Compile go build Run without compi

Paweł Krupski 1 Nov 8, 2021
Goji is a minimalistic and flexible HTTP request multiplexer for Go (golang)

Goji Goji is a HTTP request multiplexer, similar to net/http.ServeMux. It compares incoming requests to a list of registered Patterns, and dispatches

Goji 904 Sep 14, 2022
Go Server/API micro framework, HTTP request router, multiplexer, mux

?? gorouter Go Server/API micro framework, HTTP request router, multiplexer, mux. ?? ABOUT Contributors: Rafał Lorenz Want to contribute ? Feel free t

Rafał Lorenz 133 Sep 11, 2022
A high performance HTTP request router that scales well

HttpRouter HttpRouter is a lightweight high performance HTTP request router (also called multiplexer or just mux for short) for Go. In contrast to the

Julien Schmidt 14.5k Sep 27, 2022
A benchmark suite aims to compare the performance of HTTP request routers for Go

Go HTTP Router Benchmark This benchmark suite aims to compare the performance of HTTP request routers for Go by implementing the routing structure of

null 3 Oct 25, 2021
A high performance HTTP request router that scales well

HttpRouter HttpRouter is a lightweight high performance HTTP request router (also called multiplexer or just mux for short) for Go. In contrast to the

Julien Schmidt 13.5k Dec 9, 2021
Go HTTP request router and web framework benchmark

Go HTTP Router Benchmark This benchmark suite aims to compare the performance of HTTP request routers for Go by implementing the routing structure of

Peter Kieltyka 26 Sep 21, 2022