-
Notifications
You must be signed in to change notification settings - Fork 74
HTTP Test Harness
Thomas Cherryhomes edited this page Feb 13, 2021
·
1 revision
The following Go program can be used as a test harness for GET and POST requests.
For GET requests, each query parameter is printed to stdout. The string "This is the GET body." is returned as the body of the GET request.
For POST requests, the body of the POST request is printed to stdout. The string "This is the POST body." is returned as the body of the POST request.
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
)
func helloWorld(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
switch r.Method {
case "GET":
for k, v := range r.URL.Query() {
fmt.Printf("%s: %s\n",k, v)
}
w.Write([]byte("This is the GET body.\r\n"))
case "POST":
reqBody, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", reqBody)
w.Write([]byte("This is the POST body.\r\n"))
default:
w.WriteHeader(http.StatusNotImplemented)
w.Write([]byte(http.StatusText(http.StatusNotImplemented)))
}
}
func main() {
http.HandleFunc("/", helloWorld)
http.ListenAndServe(":8000", nil)
}
Copyright 2024 Contributors to the FujiNetWIFI project.
Join us on Discord: https://discord.gg/7MfFTvD
- Home
- What is FujiNet?
- The Definition of Done
- Board bring up for FujiNet Platform.IO code
- The Complete Linux CLI Guide
- The Complete macOS CLI Guide
- Development Env for Apps
- FujiNet-Development-Guidelines
- System Quickstarts
- FujiNet Flasher
- Setting up a TNFS Server
- FujiNet Configuration File: fnconfig.ini
- AppKey Registry - SIO Command $DC Open App Key
- CP-M Support
- BBS
- Official Hardware Versions
- Prototype Board Revisions
- FujiNet Development Guidelines
- Atari Programming
- Apple Programming
- C64 Programming
- ADAM Programming
- Testing Plan
- Hacker List
- FujiNet VirtualMachine