Skip to content

Commit

Permalink
added response header endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
alexadrake committed Mar 14, 2023
1 parent dff6e93 commit f0129a5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
2 changes: 2 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"github.com/speakeasy-api/speakeasy-auth-test-service/internal/responseHeaders"
"log"
"net/http"

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

log.Println("Listening on :8080")
if err := http.ListenAndServe(":8080", r); err != nil {
Expand Down
28 changes: 28 additions & 0 deletions internal/responseHeaders/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package responseHeaders

import (
"encoding/json"
"github.com/speakeasy-api/speakeasy-auth-test-service/internal/utils"
"io"
"net/http"
)

func HandleVendorJsonResponseHeaders(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body)
if err != nil {
utils.HandleError(w, err)
return
}

var req interface{}
if err := json.Unmarshal(body, &req); err != nil {
utils.HandleError(w, err)
return
}

w.Header().Set("Content-Type", "application/vnd.api+json; charset=utf-8")

if err := json.NewEncoder(w).Encode(req); err != nil {
utils.HandleError(w, err)
}
}

0 comments on commit f0129a5

Please sign in to comment.