Giter Site home page Giter Site logo

r2's Introduction

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
  • 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.

r2's People

Contributors

aofei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.