Skip to content

Commit f0129a5

Browse files
author
alexadrake
committed
added response header endpoint
1 parent dff6e93 commit f0129a5

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

cmd/server/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"github.com/speakeasy-api/speakeasy-auth-test-service/internal/responseHeaders"
45
"log"
56
"net/http"
67

@@ -16,6 +17,7 @@ func main() {
1617
}).Methods(http.MethodGet)
1718
r.HandleFunc("/auth", auth.HandleAuth).Methods(http.MethodPost)
1819
r.HandleFunc("/requestbody", requestbody.HandleRequestBody).Methods(http.MethodPost)
20+
r.HandleFunc("/vendorjson", responseHeaders.HandleVendorJsonResponseHeaders).Methods(http.MethodGet)
1921

2022
log.Println("Listening on :8080")
2123
if err := http.ListenAndServe(":8080", r); err != nil {

internal/responseHeaders/service.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package responseHeaders
2+
3+
import (
4+
"encoding/json"
5+
"github.com/speakeasy-api/speakeasy-auth-test-service/internal/utils"
6+
"io"
7+
"net/http"
8+
)
9+
10+
func HandleVendorJsonResponseHeaders(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+
var req interface{}
18+
if err := json.Unmarshal(body, &req); err != nil {
19+
utils.HandleError(w, err)
20+
return
21+
}
22+
23+
w.Header().Set("Content-Type", "application/vnd.api+json; charset=utf-8")
24+
25+
if err := json.NewEncoder(w).Encode(req); err != nil {
26+
utils.HandleError(w, err)
27+
}
28+
}

0 commit comments

Comments
 (0)