From a5e066b5a931af856940decd6e20155cac544017 Mon Sep 17 00:00:00 2001 From: brayancasanova Date: Tue, 11 Nov 2025 22:45:39 +0000 Subject: [PATCH] lab6 api --- newapi.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 newapi.go diff --git a/newapi.go b/newapi.go new file mode 100644 index 0000000..e17f005 --- /dev/null +++ b/newapi.go @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" + "net/http" +) + +func main() { + http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "Hello from GET method!") + }) + + http.HandleFunc("/data", func(w http.ResponseWriter, r *http.Request) { + if r.Method == "POST" { + fmt.Fprintf(w, "Data received via POST!") + } else { + fmt.Fprintf(w, "Please use POST method.") + } + }) + + fmt.Println("Server running on :8080") + http.ListenAndServe(":8080", nil) +}