Documentation ¶
Overview ¶
Package api has code that offers a REST API for the applications that want to push messages.
Index ¶
Constants ¶
View Source
const JSONMediaType = "application/json"
View Source
const MaxRequestBodyBytes = 4 * 1024
Variables ¶
View Source
var ( ErrNoContentLengthProvided = &APIError{ http.StatusLengthRequired, invalidRequest, "A Content-Length must be provided", } ErrRequestBodyEmpty = &APIError{ http.StatusBadRequest, invalidRequest, "Request body empty", } ErrRequestBodyTooLarge = &APIError{ http.StatusRequestEntityTooLarge, invalidRequest, "Request body too large", } ErrWrongContentType = &APIError{ http.StatusUnsupportedMediaType, invalidRequest, "Wrong content type, should be application/json", } ErrWrongRequestMethod = &APIError{ http.StatusMethodNotAllowed, invalidRequest, "Wrong request method, should be POST", } ErrMalformedJSONObject = &APIError{ http.StatusBadRequest, invalidRequest, "Malformed JSON Object", } ErrCouldNotReadBody = &APIError{ http.StatusBadRequest, ioError, "Could not read request body", } ErrMissingData = &APIError{ http.StatusBadRequest, invalidRequest, "Missing data field", } ErrUnknownChannel = &APIError{ http.StatusBadRequest, unknownChannel, "Unknown channel", } ErrUnknown = &APIError{ http.StatusInternalServerError, internalError, "Unknown error", } ErrCouldNotStoreNotification = &APIError{ http.StatusServiceUnavailable, unavailable, "Could not store notification", } )
Well-known prebuilt API errors
Functions ¶
func MakeHandlersMux ¶
func MakeHandlersMux(store store.PendingStore, broker broker.BrokerSending, logger logger.Logger) http.Handler
MakeHandlersMux makes a handler that dispatches for the various API endpoints.
Types ¶
type APIError ¶
type APIError struct { // http status code StatusCode int `json:"-"` // machine readable label ErrorLabel string `json:"error"` // human message Message string `json:"message"` }
APIError represents a API error (both internally and as JSON in a response).
type Broadcast ¶
type Broadcast struct { Channel string `json:"channel"` ExpireAfter uint8 `json:"expire_after"` Data json.RawMessage `json:"data"` }
Broadcast request JSON object.
type BroadcastHandler ¶
type BroadcastHandler state
func (*BroadcastHandler) ServeHTTP ¶
func (h *BroadcastHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request)
Click to show internal directories.
Click to hide internal directories.