Medeina

Go HTTP routing tree based on HttpRouter. Inspired by Roda and Cuba.
Alternatives To Medeina
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Httprouter15,2863,9271,69013 days ago12August 14, 202083bsd-3-clauseGo
A high performance HTTP request router that scales well
Routing7,41799,2591,1153 days ago531June 08, 2022mitPHP
Maps an HTTP request to a set of configuration variables
Go Restful4,7646,1102,1452 months ago96July 21, 20224mitGo
package for building REST-style Web Services using Go
Compojure4,018
6,265a month ago63April 15, 20187epl-1.0Clojure
A concise routing library for Ring/Clojure
Klein.php2,630362659 months ago9February 01, 201797mitPHP
A fast & flexible router
Aqueduct2,3573522 years ago38June 01, 2020180bsd-2-clauseDart
Dart HTTP server framework for building REST APIs. Includes PostgreSQL ORM and OAuth2 provider.
Siler1,126198a year ago43January 27, 202128mit
⚡ Flat-files and plain-old PHP functions rockin'on as a set of general purpose high-level abstractions.
Awesome Micro1,064
a year ago
A collection of awesome things regarding zeit's micro.
Spock652
7210 months ago62June 15, 201829Haskell
Another Haskell web framework for rapid development
Microwebsrv529
5 months ago8mitPython
A micro HTTP Web server that supports WebSockets, html/python language templating and routing handlers, for MicroPython (used on Pycom modules & ESP32)
Alternatives To Medeina
Select To Compare


Alternative Project Comparisons
Readme

Medeina Build Status GoDoc Coverage Status docs examples dependencies

Medeina is a Go routing tree based on HttpRouter and inspired by Ruby's Roda and Cuba. It allows to define the HTTP routes of your web application as a tree, operating on the current route at any point of the tree.

As stated in Roda's website, "this allows you to have much DRYer code". All the routes can have all the features of HttpRouter: named paramaters, catch-all parameters, etc.

Actually, Medeina inherits all the performance and flexibility you love in HttpRouter (great job, Julien!).

Status

Medeina is fully functional and tested but it's still green and young. It may lack some useful functionality. If you use HttpRouter, give Medeina a try. All real world experience is welcome.

Install

go get github.com/imdario/medeina

// use in your .go code
import (
    "github.com/imdario/medeina"
)

Usage

Check the docs and these examples:

// From Roda's site
r := medeina.NewMedeina()
r.GET(func() {
    r.Is("", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
        http.Redirect(w, r, "/hello", http.StatusFound)
    })
    r.On("hello", func() {
        r.Is("world", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
            fmt.Fprintf(w, "Hello world!")
        })
        r.Is("", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
            fmt.Fprintf(w, "Hello!")
        })
    })
})

log.Fatal(http.ListenAndServe(":8080", r))

And this for a quick and dirty "REST-like" API (ignore the fact that I'm using a single method to handle everything):

endpoints := []string {
    "department", "employee", "project"
}
r := medeina.NewMedeina()
r.GET(func() {
    r.Is("", Index)
})
for endpoint := range endpoints {
    r.On(endpoint, func() {
        r.GET(func() {
            r.Is(":id", Model)
        })
        r.POST(func() {
            r.Is("", Model)
        })
        r.PUT(func() {
            r.Is("", Model)
        })
        r.DELETE(func() {
            r.Is(":id", Model)
        })
    })
}

log.Fatal(http.ListenAndServe(":8080", r))

Or it's "shorter" (YMMV) form:

endpoints := []string {
    "department", "employee", "project"
}
r := medeina.NewMedeina()
r.Is("", Index, medeina.GET)
for endpoint := range endpoints {
    r.On(endpoint, func() {
        r.Is("", Model, medeina.POST, medeina.PUT)
        r.Is(":id", Model, medeina.GET, medeina.DELETE)
    })
}

log.Fatal(http.ListenAndServe(":8080", r))

What does "" means? It matches the current path in your route. It's a way to easily match the scope itself as canonical URL.

Why HttpRouter?

Because it's the most fast and flexible Go HTTP router around the town and a good one to start. If you want Medeina to work with your preferred option, patches are welcome!

If you don't know HttpRouter, please check it out. You won't regret it.

Why is it called Medeina?

From Wikipedia:

Medeina or Medeinė (derived from medis (tree) and medė (forest)), [...] is one of the main deities in the Lithuanian mythology, similar to Latvian Meža Māte. She is a ruler of forests, trees and animals. Her sacred animal is a hare.

Hey, we were talking about trees. It fits right! Also, this project can join my other ones, also called by names starting by 'm': Mergo, Minshu, mqqsig192, etc. Don't ask, it wasn't on purpose.

Contact me

If I can help you, you have an idea or you are using Medeina in your projects, don't hesitate to drop me a line (or a pull request): @im_dario

About

Written by Dario Castañé.

License

MIT license.

Popular Routing Projects
Popular Http Projects
Popular Networking Categories

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Go
Http
Routing