Community Snippets

Go HTTP JSON Server

by Abba Sali Aboubakar Mamate

Go
#go#http#api#json
package main

import (
	"encoding/json"
	"net/http"
)

func main() {
	http.HandleFunc("/api/health", func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json")
		json.NewEncoder(w).Encode(map[string]string{"status": "ok"})
	})
	http.ListenAndServe(":8080", nil)
}

Comments (0)

No comments yet.

Sign in to leave a comment.