Popularity
2.5
Growing
Activity
0.0
Stable
36
2
0

Programming language: Go

formjson alternatives and similar packages

Based on the "Actual middlewares" category.
Alternatively, view formjson alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of formjson or a related project?

Add another 'Actual middlewares' Package

README

Go JSON handler godoc license build

FormJSON is a net/http handler implementing content negotiation for posted data in order to transparently expose posted JSON as if it was application/x-www-form-urlencoded. The posted data is then available using built-in r.FormValue("key")'s http.Request method.

To match capabilities of application/x-www-form-urlencoded, only single depth JSON object with string as keys and values is supported.

Usage

package main

import (
    "net/http"
    "fmt"

    "github.com/rs/formjson"
)

func main() {
    h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        body := fmt.Sprintf("Hello %s!", r.FormValue("name"))
        w.Write([]byte(body))
    })

    handler := formjson.Handler(h)
    http.ListenAndServe(":8080", handler)
}

Then this request:

curl -H "Content-Type:application/json" -d '{"name":"World"}' :8080

is now equivalent to this one:

curl -d name=World :8080

Licenses

All source code is licensed under the MIT License.


*Note that all licence references and agreements mentioned in the formjson README section above are relevant to that project's source code only.