Skip to content

Commit 8632ebb

Browse files
feat: add post body reflection endpoint
1 parent 3d1bdff commit 8632ebb

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

cmd/server/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/speakeasy-api/speakeasy-api-test-service/internal/middleware"
1313
"github.com/speakeasy-api/speakeasy-api-test-service/internal/pagination"
1414
"github.com/speakeasy-api/speakeasy-api-test-service/internal/readonlywriteonly"
15+
"github.com/speakeasy-api/speakeasy-api-test-service/internal/reflect"
1516
"github.com/speakeasy-api/speakeasy-api-test-service/internal/responseHeaders"
1617
"github.com/speakeasy-api/speakeasy-api-test-service/internal/retries"
1718

@@ -52,6 +53,7 @@ func main() {
5253
r.HandleFunc("/eventstreams/differentdataschemas", eventstreams.HandleEventStreamDifferentDataSchemas).Methods(http.MethodPost)
5354
r.HandleFunc("/clientcredentials/token", clientcredentials.HandleTokenRequest).Methods(http.MethodPost)
5455
r.HandleFunc("/clientcredentials/authenticatedrequest", clientcredentials.HandleAuthenticatedRequest).Methods(http.MethodPost)
56+
r.HandleFunc("/reflect", reflect.HandleReflect).Methods(http.MethodPost)
5557

5658
handler := middleware.Fault(r)
5759

internal/reflect/service.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package reflect
2+
3+
import (
4+
"io"
5+
"net/http"
6+
7+
"github.com/speakeasy-api/speakeasy-api-test-service/internal/utils"
8+
)
9+
10+
func HandleReflect(w http.ResponseWriter, r *http.Request) {
11+
body, err := io.ReadAll(r.Body)
12+
if err != nil {
13+
utils.HandleError(w, err)
14+
return
15+
}
16+
17+
contentType := r.Header.Get("Content-Type")
18+
19+
if contentType != "" {
20+
w.Header().Set("Content-Type", contentType)
21+
}
22+
23+
if _, err := w.Write(body); err != nil {
24+
utils.HandleError(w, err)
25+
}
26+
}

0 commit comments

Comments
 (0)