From 7bcb9b639b064e17b13f99fb353448166a1ed145 Mon Sep 17 00:00:00 2001 From: Baitinq Date: Wed, 1 May 2024 21:27:15 +0200 Subject: rest-api: return request body as string --- src/rest-api/cmd/main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/rest-api/cmd/main.go b/src/rest-api/cmd/main.go index af72f82..56cc6a3 100644 --- a/src/rest-api/cmd/main.go +++ b/src/rest-api/cmd/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "io" "net/http" ) @@ -12,5 +13,10 @@ func main() { } func handleRequest(w http.ResponseWriter, r *http.Request) { - fmt.Fprint(w, "Hello, World!", r.Body) + bytes, err := io.ReadAll(io.Reader(r.Body)) + if err != nil { + panic(err) + } + + fmt.Fprint(w, "Hello, World!", string(bytes)) } -- cgit 1.4.1