Is gorilla/mux a mainly used package to write RESTful API?

I’m new at Go, when I’m finding how to write RESTful API in Go, I find following two tutorials mention the gorilla/mux package,


is this package a mainly used package to wirte RESTful API?

And is there way to quickly judge whether a pakage is mostly used by developers in specific domain and useful or not?

Can I judge just by how many stars the github project has?

(the gorilla/mux has 5 thousand stars : https://github.com/gorilla/mux)

1 Like

I don’t know if gorilla/mux is the most used in RESTful API programming but is a very good choice. Github stars can be a barometer for popularity but you must try it to see if fit your needs.

2 Likes

In my opinion gorilla/mux is fine if you do not build anything large (but even in such case u can still use it).
For a little bit bigger project I would suggest to use gin-gonic/gin. What convinced me to use gin is the possibility to
group routes by version for example: https://github.com/gin-gonic/gin#grouping-routes

1 Like

I like “gorilla/mux”, this is great for my applications but depends on always the context.

2 Likes

Gorilla has subrouters for grouping routes.

2 Likes

Ahh you are right. I did not spot that when I was evaluating Gorilla.
Indeed we can write something like this:

r := mux.NewRouter()
post := r.PathPrefix("/posts/{id}").Subrouter()
post.Methods("GET").Path("/edit").HandlerFunc(PostEditHandler)
post.Methods("GET").HandlerFunc(PostShowHandler)
post.Methods("POST").HandlerFunc(PostUpdateHandler)

Thx for pointing this out.

3 Likes

I don’t like that gin changes handlers’ signature, but it is quite powerful, for example for middleware chaining.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.