cosmos-sdk/client/rest/rest.go
Amaury 13bc504bec
docs: Add REST endpoints migration guide (#8011)
* Add REST endpoints migration guide

* add bank, distrib, evidence

* Add slashing, mint

* Add staking

* Add query

* Add todo

* Typos

* Add link to interact node

* grammar

* Better wording

* Update docs/migrations/rest.md

Co-authored-by: Robert Zaremba <robert@zaremba.ch>

* Update docs/migrations/rest.md

* Add footnote

Co-authored-by: Robert Zaremba <robert@zaremba.ch>
2020-11-24 14:34:20 +00:00

33 lines
1.2 KiB
Go

package rest
import (
"net/http"
"github.com/gorilla/mux"
)
// DeprecationURL is the URL for migrating deprecated REST endpoints to newer ones.
// TODO Switch to `/` (not `/master`) once v0.40 docs are deployed.
// https://github.com/cosmos/cosmos-sdk/issues/8019
const DeprecationURL = "https://docs.cosmos.network/master/migrations/rest.html"
// addHTTPDeprecationHeaders is a mux middleware function for adding HTTP
// Deprecation headers to a http handler
func addHTTPDeprecationHeaders(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Deprecation", "true")
w.Header().Set("Link", "<"+DeprecationURL+">; rel=\"deprecation\"")
w.Header().Set("Warning", "199 - \"this endpoint is deprecated and may not work as before, see deprecation link for more info\"")
h.ServeHTTP(w, r)
})
}
// WithHTTPDeprecationHeaders returns a new *mux.Router, identical to its input
// but with the addition of HTTP Deprecation headers. This is used to mark legacy
// amino REST endpoints as deprecated in the REST API.
func WithHTTPDeprecationHeaders(r *mux.Router) *mux.Router {
subRouter := r.NewRoute().Subrouter()
subRouter.Use(addHTTPDeprecationHeaders)
return subRouter
}