Skip to content
Snippets Groups Projects

HTTP Negotiation

Installation

go get gitlab.schukai.com/oss/libraries/go/application/http-negotiation

Note: This library uses Go Modules to manage dependencies.

What do this library?

This library provides a simple way to negotiate the content type of HTTP request.

It supports:

Usage

package main

import (
	"net/http"
	"gitlab.schukai.com/oss/libraries/go/application/http-negotiation"
)

func handleRequest(w http.ResponseWriter, r *http.Request) {
	n := negotiation.New(r.Header)

	if n.Type("application/json") == "application/json" {
		w.Header().Set("Content-Type", "application/json")
		w.Write([]byte(`{"message": "Hello World!"}`))
		return
	}

}

Contributing

Merge requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

AGPL-3.0