Skip to content

Commit

Permalink
feat(dev-server): Support polling API (#466)
Browse files Browse the repository at this point in the history
implement /sdk/latest-all
  • Loading branch information
ynishinaka authored Jan 27, 2025
1 parent e1a448b commit 8917573
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions internal/dev_server/sdk/polling.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package sdk

import (
"encoding/json"
"net/http"

"github.com/pkg/errors"
)

func LatestAll(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
allFlags, err := GetAllFlagsFromContext(ctx)
if err != nil {
WriteError(ctx, w, errors.Wrap(err, "failed to get flag state"))
return
}
serverFlags := ServerAllPayloadFromFlagsState(allFlags)
enc := json.NewEncoder(w)
err = enc.Encode(serverFlags.Data)
if err != nil {
WriteError(ctx, w, errors.Wrap(err, "failed to encode response"))
return
}
}
1 change: 1 addition & 0 deletions internal/dev_server/sdk/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func BindRoutes(router *mux.Router) {
router.HandleFunc("/mobile/events/diagnostic", DevNull)

router.Handle("/all", GetProjectKeyFromAuthorizationHeader(http.HandlerFunc(StreamServerAllPayload)))
router.Handle("/sdk/latest-all", GetProjectKeyFromAuthorizationHeader(http.HandlerFunc(LatestAll)))

router.PathPrefix("/sdk/flags/{flagKey}").
Methods(http.MethodGet).
Expand Down

0 comments on commit 8917573

Please sign in to comment.