- Golang JSON REST API using Gorilla Mux as the HTTP router and URL matcher. Tutorial code from Devstackr, Youtube video: Build a RESTful HTTP API in Golang w/ Mux
- Note: to open web links in a new window use: ctrl+click on link
- Go’s default request handler signature is
func (w http.ResponseWriter, r *http.Request)
- go version go1.14 windows/amd64 programming language
- Gorilla web toolkit HTTP request multiplexer
- You need to download & install Go
- Set the path of your workspace location in your platform Environment Variables
- Install Go in Visual Studio
- Install the Go toolchain in Visual Studio
- function to get a post using the Gorilla mux, with pointer type *http.Request
func getPost(w http.ResponseWriter, r *http.Request) {
// get the ID of the post from the route parameter
// golang method strconv.Atoi is equivalent to ParseInt(s, 10, 0), converted to type int.
ar idParam string = mux.Vars(r)["id"]
id, err := strconv.Atoi(idParam)
if err != nil {
// there was an error
w.WriteHeader(400)
w.Write([]byte("ID could not be converted to integer"))
return
}- Status: Working
- To-do: Nothing
- All code from Devstackr, Youtube video: Build a RESTful HTTP API in Golang w/ Mux
- Hugo Johnsson: Medium article REST-API with Golang and Mux
- Go Web Examples: Routing (using gorilla/mux)
- This project is licensed under the terms of the MIT license.
- Repo created by ABateman, email: gomezbateman@yahoo.com
