Skip to content
/ jqmux Public

Go HTTP Multiplexer routing on JSON http request bodies via jq queries

License

Notifications You must be signed in to change notification settings

donatj/jqmux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jqmux

Build Status GoDoc Go Report Card

An HTTP multiplexer which routes based on the incoming requests JSON body using the jq syntax of JSON value filtering.

A particularly fruitful usecase for this is webhook routing.

Limitations

This utilizes the library github.com/savaki/jq for it's jq parsing. While it is very fast it is not fully featured, so more complicated jq queries might not work. More information about it's workings and expected values can be found there.

Example

The first handler is executed if the body matches {"action": "opened"} whereas the second is executed if the body matches {"action": "synchronize"}

package main

import (
	"net/http"

	"github.com/donatj/jqmux"
)

func main() {
	mux := jqmux.NewMux()

	mux.HandleFunc(`.action`, `"opened"`, func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte(`body "action" was "opened"`))
	})

	mux.HandleFunc(`.action`, `"synchronize"`, func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte(`body "action" was "synchronize"`))
	})

	http.ListenAndServe(":80", mux)
}