Utilities for a JSON-based API.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Matt Baer 38cdc56928 Add ReqJSON func for determining JSON requests 6 years ago
.gitignore Add text editor temp files to gitignore 8 years ago
LICENSE Initial commit 8 years ago
README.md Add IRC badge to README 7 years ago
doc.go Rename impart.go to doc.go 7 years ago
errors.go Add func and package comments 7 years ago
request.go Add ReqJSON func for determining JSON requests 6 years ago
response.go Add WriteRedirect helper func 6 years ago



MIT license #writeas on freenode Public Slack discussion

impart is a library for the final layer between the API and the consumer. It’s used in the latest Write.as and HTMLhouse APIs.

We’re still in the early stages of development, so there may be breaking changes.

Example use

package main

import (

type handlerFunc func(w http.ResponseWriter, r *http.Request) error

func main() {
	http.HandleFunc("/", handle(index))
	http.ListenAndServe("", nil)

func index(w http.ResponseWriter, r *http.Request) error {
	fmt.Fprintf(w, "Hello world!")

	return nil

func handle(f handlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		handleError(w, r, func() error {
			// Do authentication...

			// Handle the request
			err := f(w, r)

			// Log the request and result...

			return err

func handleError(w http.ResponseWriter, r *http.Request, err error) {
	if err == nil {

	if err, ok := err.(impart.HTTPError); ok {
		impart.WriteError(w, err)

	impart.WriteError(w, impart.HTTPError{http.StatusInternalServerError, "Internal server error :("})