My "functional" wrapper around Golang's net/http server stuff
The default net/http interface:
type Handler interface {
ServeHTTP(ResponseWriter, *Request)
}RSVP's interface:
type Handler interface {
ServeHTTP(h http.Header, r *http.Request) Response
}- Content Negotiation. RSVP will attempt to provide the data in a supported media-type that is requested via the Accept header, or even the URL's file extension in the case of GET requests:
-
application/json -
text/html -
text/plain -
application/octet-stream -
application/xml -
application/vnd.golang.gob(Golang's encoding/gob) -
application/vnd.msgpack(optional extension behind -tags=rsvp_msgpack) - Others?
-
It's easy for me to lose track of what I've written to http.ResponseWriter. Occasionally receiving the old http: multiple response.WriteHeader calls
With this library I just return a value, which I can only ever do once, to execute an HTTP response write. Why write responses with a weird mutable reference from goodness knows where? YEUCH!
Having to remember to return separately from resolving the response? *wretch*
if r.Method != http.MethodPut {
http.Error(w, "Use PUT", http.StatusMethodNotAllowed)
return
}Not with RSVP 🫠
if r.Method != http.MethodPut {
return rsvp.Response{Status: http.StatusMethodNotAllowed, Body: "Use PUT"}
}(Wrapping this with your own convenience method, i.e. func ErrorMethodNotAllowed(message string) rsvp.Response is encouraged. You get to decide for yourself how errors are represented)
- You can see it in action on my stupid little blog site, brightscroll.net. For instance, https://brightscroll.net/posts/2025-06-30.md vs. https://brightscroll.net/posts/2025-06-30.md.txt