Skip to content
/ nova Public
forked from MordFustang21/nova

nova is an HTTP request multiplexer. It matches the URL of each incoming request against a list of registered patterns and calls the handler for the pattern that most closely matches the URL. As well as providing some nice logging and response features.

License

Notifications You must be signed in to change notification settings

reilg/nova

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Supernova Logo

GoDoc Go Report Card Build Status

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.

Start using it

  1. Download and install
$ go get github.com/MordFustang21/nova
  1. Import it into your code
import "github.com/MordFustang21/nova"

Basic Usage

http://localhost:8080/hello

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)
}

Retrieving parameters

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)
}

Returning Errors

http://localhost:8080/hello

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)
	
}

About

nova is an HTTP request multiplexer. It matches the URL of each incoming request against a list of registered patterns and calls the handler for the pattern that most closely matches the URL. As well as providing some nice logging and response features.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%