nova is a mux for http while we don't claim to be the best or fastest we provide a lot of tools and features that enable you to be highly productive and help build up your api quickly and efficiently.
*Note nova's exported API interface will continue to change in unpredictable, backwards-incompatible ways until we tag a v1.0.0 release.
- Download and install
$ go get github.com/MordFustang21/nova
- Import it into your code
import "github.com/MordFustang21/nova"
package main
import (
"github.com/MordFustang21/nova"
"net/http"
)
func main() {
s := nova.New()
s.Get("/hello", func(request *nova.Request) error {
return request.Send("world")
})
http.ListenAndServe(":8080", s)
}
http://localhost:8080/hello/world
package main
import (
"github.com/MordFustang21/nova"
"net/http"
)
func main() {
s := nova.New()
s.Get("/hello/:text", func(request *nova.Request) error {
t := request.RouteParam("text")
return request.Send(t)
})
http.ListenAndServe(":8080", s)
}
package main
import (
"github.com/MordFustang21/nova"
"net/http"
)
func main() {
s := nova.New()
s.Post("/hello", func(request *nova.Request) error {
r := struct {
World string
}{}
// ReadJSON will attempt to unmarshall the json from the request body into the given struct
err := request.ReadJSON(&r)
if err != nil {
return request.Error(http.StatusBadRequest, "couldn't parse request", err.Error())
}
// JSON will marshall the given object and marshall into into the response body
return request.JSON(http.StatusOK, r)
})
http.ListenAndServe(":8080", s)
}