Important
|
This repository is no longer maintained here. It has been moved to
|
Serializing middleware stack for building APIs in Go.
Install
$ go get gopkg.in/foxcapades/go-midl.v1/pkg/midl
package main
import (
"net/http"
"gopkg.in/foxcapades/go-midl.v1/pkg/midl"
)
func main() {
http.Handle("/", midl.JSONAdapter(
NewSessionHandler(),
NewInputValidator(),
NewController(),
))
log.Fatal(http.ListenAndServe(":8080", nil))
}
Example usage using the demo available in the cmd/test
package.
$ go run cmd/test/*.go &
$ curl -iX POST -d'{}' localhost:8080/combine
HTTP/1.1 400 Bad Request
Content-Type: application/json
Date: Tue, 29 May 2018 23:33:56 GMT
Content-Length: 51
["start: start is required","end: end is required"]
$ curl -iX POST -d'{"start":["a","b"], "end":["c","d"]}' localhost:8080/combine
HTTP/1.1 200 OK
Content-Type: application/json
Custom-Header: some value
Date: Tue, 29 May 2018 23:34:39 GMT
Content-Length: 32
{"combos":["ac","ad","bc","bd"]}