Simple and fast framework to create awesome REST APIs in seconds!
- Incredible fast routing
- Optimized for dynamic path with multiple parameters
- Namad paramters
- Parameter pool for 0 allocations and max speed
- Middlwares (included: cors, no-cache, simple logging)
- Cascade routers for complex API
- Panic handler
- Static files
All this speed comes to a cost, a good amout of used memory due to the pool and a really slow initialization process.
Please notice that adding path after initialization is not a good practice because it leads to temporary performance degradation. Inizialitation is not designed to be fast, all the speed comes after the cost of booting everything!
This simple code is just a sample to demostrate how simple and clean is the code to create a REST API with pantofola-rest
.
import (
"fmt"
"net/http"
pantofola "github.com/rickycorte/pantofola-rest/router"
)
// hello is our first handler!
func hello(w http.ResponseWriter, _ *http.Request, _ *ParameterList) {
w.WriteHeader(200)
fmt.Fprintf(w, "Hi sen(pi) <3")
}
// generic handler for a parametric route that prints available values by name
func writeData(w http.ResponseWriter, r *http.Request, p *pantofola.ParameterList) {
w.WriteHeader(200)
fmt.Fprintf(w, r.RequestURI+"\n\nUser: "+p.Get("user")
+"\nActivity: "+p.Get("activity")+"\nComment: "+p.Get("comment"))
}
func main() {
mainRouter := router.MakeRouter() // create the main router used by our app
// we add our handler as the main router
mainRouter.GET("/hello", hello)
// let's make some parametric handlers
mainRouter.GET("/activity/:user", writeData)
mainRouter.GET("/activity/:user/:activity", writeData)
mainRouter.GET("/activity/:user/:activity/comments/:comment", writeData)
http.ListenAndServe(":8080", mainRouter) // start the server end enjoy your REST API!
}
Visit wiki pages to learn how to use all the features of pantofola-rest