All Projects → gernest → Alien

gernest / Alien

Licence: mit
A lightweight and fast http router from outer space

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Alien

Simple Php Router
Simple, fast and yet powerful PHP router that is easy to get integrated and in any project. Heavily inspired by the way Laravel handles routing, with both simplicity and expand-ability in mind.
Stars: ✭ 279 (+142.61%)
Mutual labels:  lightweight, router
Mu
A tweet-sized PHP micro-router
Stars: ✭ 229 (+99.13%)
Mutual labels:  lightweight, router
Deko3d
Homebrew low level graphics API for Nintendo Switch (Nvidia Tegra X1)
Stars: ✭ 103 (-10.43%)
Mutual labels:  lightweight
Microproxy
Lightweight non-caching HTTP(S) proxy server
Stars: ✭ 112 (-2.61%)
Mutual labels:  lightweight
Pilot
Pilot — multifunction JavaScript router.
Stars: ✭ 109 (-5.22%)
Mutual labels:  router
Moon Api Gateway
Asynchronous API Gateway with spring boot 2.1, servlet 4.0, jetty 9 client
Stars: ✭ 104 (-9.57%)
Mutual labels:  lightweight
Php Router
simple and flexible Router class for PHP. with Controllers and Middlewares support.
Stars: ✭ 111 (-3.48%)
Mutual labels:  router
Routes
typed bidirectional routes for OCaml/ReasonML web applications
Stars: ✭ 102 (-11.3%)
Mutual labels:  router
Router
🍭灵活的组件化路由框架.
Stars: ✭ 1,502 (+1206.09%)
Mutual labels:  router
Docker Openwrt
OpenWrt running in Docker
Stars: ✭ 107 (-6.96%)
Mutual labels:  router
Rxviper
Android micro framework for developing apps based on clean VIPER architecture.
Stars: ✭ 112 (-2.61%)
Mutual labels:  router
Gin
Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
Stars: ✭ 53,971 (+46831.3%)
Mutual labels:  router
Cherrytree
A flexible nested router.
Stars: ✭ 105 (-8.7%)
Mutual labels:  router
Sme Router
A lightweight router lib that implement with express route style
Stars: ✭ 112 (-2.61%)
Mutual labels:  router
Cottage
Simple, fast HTTP router on koa.js.
Stars: ✭ 103 (-10.43%)
Mutual labels:  router
Netcopa
Network Configuration Parser
Stars: ✭ 112 (-2.61%)
Mutual labels:  router
Router
A simple, compact and fast router package to process HTTP requests
Stars: ✭ 102 (-11.3%)
Mutual labels:  router
Router.js
Router.js is a simple and powerful javascript library to handle routing
Stars: ✭ 107 (-6.96%)
Mutual labels:  router
Scalajs React
Facebook's React on Scala.JS
Stars: ✭ 1,524 (+1225.22%)
Mutual labels:  router
Tieguanyin
Activity Builder.
Stars: ✭ 113 (-1.74%)
Mutual labels:  router

Alien Coverage Status Build Status GoDoc Go Report Card

Alien is a lightweight http router( multiplexer) for Go( Golang ), made for humans who don't like magic.

Documentation docs

Features

  • fast ( see the benchmarks, or run them yourself)
  • lightweight ( just a single file read all of it in less than a minute)
  • safe( designed with concurrency in mind)
  • middleware support.
  • routes groups
  • no external dependency( only the standard library )

Motivation

I wanted a simple, fast, and lightweight router that has no unnecessary overhead using the standard library only, following good practices and well tested code( Over 90% coverage)

Installation

go get github.com/gernest/alien

Usage

normal static routes


package main

import (
	"log"
	"net/http"

	"github.com/gernest/alien"
)

func main() {
	m := alien.New()
	m.Get("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("hello world"))
	})
	log.Fatal(http.ListenAndServe(":8090", m))
}

visiting your localhost at path / will print hello world

named params


package main

import (
	"log"
	"net/http"

	"github.com/gernest/alien"
)

func main() {
	m := alien.New()
	m.Get("/hello/:name", func(w http.ResponseWriter, r *http.Request) {
		p := alien.GetParams(r)
		w.Write([]byte(p.Get("name")))
	})
	log.Fatal(http.ListenAndServe(":8090", m))
}

visiting your localhost at path /hello/tanzania will print tanzania

catch all params

package main

import (
	"log"
	"net/http"

	"github.com/gernest/alien"
)

func main() {
	m := alien.New()
	m.Get("/hello/*name", func(w http.ResponseWriter, r *http.Request) {
		p := alien.GetParams(r)
		w.Write([]byte(p.Get("name")))
	})
	log.Fatal(http.ListenAndServe(":8090", m))
}

visiting your localhost at path /hello/my/margicl/sheeplike/ship will print my/margical/sheeplike/ship

middlewares

Middlewares are anything that satisfy the interface func(http.Handler)http.Handler . Meaning you have thousands of middlewares at your disposal, you can use middlewares from many golang http frameworks on alien(most support the interface).


package main

import (
	"log"
	"net/http"

	"github.com/gernest/alien"
)

func middleware(h http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("hello middlware"))
	})
}

func main() {
	m := alien.New()
	m.Use(middleware)
	m.Get("/", func(_ http.ResponseWriter, _ *http.Request) {
	})
	log.Fatal(http.ListenAndServe(":8090", m))
}

visiting your localhost at path / will print hello middleware

groups

You can group routes

package main

import (
	"log"
	"net/http"

	"github.com/gernest/alien"
)

func main() {
	m := alien.New()
	g := m.Group("/home")
	m.Use(middleware)
	g.Get("/alone", func(w http.ResponseWriter, _ *http.Request) {
		w.Write([]byte("home alone"))
	})
	log.Fatal(http.ListenAndServe(":8090", m))
}

visiting your localhost at path /home/alone will print home alone

Contributing

Start with clicking the star button to make the author and his neighbors happy. Then fork the repository and submit a pull request for whatever change you want to be added to this project.

If you have any questions, just open an issue.

Author

Geofrey Ernest @gernesti on twitter

Licence

MIT see LICENSE

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].