Understanding HTTP Server in Go #6 - Mux

Up until now, we鈥檝e been using the DefaultServeMux, but it鈥檚 time to wield more control and precision by explicitly using the http.ServeMux. Plus, we鈥檒l look at the powerful frameworks available, like Gorilla Mux and Echo, that take web server functionality to new heights. Check out previous posts: Part 1: https://surajincloud.com/understanding-http-server-in-go-basic Part 2: https://surajincloud.com/understanding-http-server-in-go-using-httpserver-struct Part 3: https://surajincloud.com/understanding-http-server-in-go-handlers Part 4: https://surajincloud.com/understanding-http-server-in-go-multiple-handlers Part 5: https://surajincloud.com/understanding-http-server-in-go-handlefunc Why do we need this? While the DefaultServeMux In Golang does a great job of handling basic routing, there will come a point where you鈥檒l want more control over your application鈥檚 routes....

September 1, 2023 路 3 min 路 Suraj Narwade

Understanding HTTP Server in Go #5 - HandleFunc

Welcome back to the fifth instalment of our in-depth exploration of creating dynamic web servers using Golang! In this post, we鈥檙e diving into the fascinating world of HandlerFunc. As you鈥檝e come to expect, GoLang provides us with an elegant and powerful way to handle requests through this mechanism. Let鈥檚 embark on this journey of discovery. Check out previous posts: Part 1: https://surajincloud.com/understanding-http-server-in-go-basic Part 2: https://surajincloud.com/understanding-http-server-in-go-using-httpserver-struct Part 3: https://surajincloud.com/understanding-http-server-in-go-handlers Part 4: https://surajincloud....

August 31, 2023 路 2 min 路 Suraj Narwade

Understanding HTTP Server in Go #4 - multiple handlers

In the previous blog post, we made our webserver useful for the first time where we printed Hello World instead of 404. Check out previous blog posts: Part 1: https://surajincloud.com/understanding-http-server-in-go-basic Part 2: https://surajincloud.com/understanding-http-server-in-go-using-httpserver-struct Part 3: https://surajincloud.com/understanding-http-server-in-go-handlers It was still useless as it was printing the same response on all the paths. Now in real real-world scenario, we won鈥檛 have just one URL right, We will need multiple paths and handlers and we still don鈥檛 have mux so now in this case we can still have multiple handlers...

August 31, 2023 路 2 min 路 Suraj Narwade

Understanding HTTP Server in Go #3 - Handlers

Welcome to the exciting third instalment of our journey into creating web servers using Golang. In our previous articles, we covered the basics of creating a web server and explored the concept of custom servers using the http.Server struct. Check out the previous blog posts: \ Part 1:* https://surajincloud.com/understanding-http-server-in-go-basic \ part 2:* https://surajincloud.com/understanding-http-server-in-go-using-httpserver-struct However, as you might have noticed, our server was, until now, simply returning a 404 error. Fear not, because in this article, we鈥檙e about to breathe life into our server by diving into the realm of handlers....

August 30, 2023 路 2 min 路 Suraj Narwade

Understanding HTTP Server in Go #2 - using http.Server struct

Welcome back to the second part of our exploration into building web servers using GoLang! In the previous blog post, we discussed creating a basic web server using the http.ListenAndServe function. However, this does not give us more control over the server config and to gain more control and flexibility over the server鈥檚 behaviour, you鈥檙e in for a treat. In this article, we鈥檒l delve into the world of custom servers by utilizing the http....

August 29, 2023 路 2 min 路 Suraj Narwade

Understanding HTTP Server in Go #1 - Basic

The net/http package in Go offers a powerful set of tools for constructing HTTP servers to handle incoming requests and send responses. In this article, we鈥檒l dive into setting up a basic HTTP server. Before we delve into the specifics, let鈥檚 familiarize ourselves with a couple of key terms: Multiplexer (or Mux): This is an essential component of an HTTP server that routes incoming requests to the appropriate handlers based on the requested paths or URLs....

August 29, 2023 路 3 min 路 Suraj Narwade

Basic Authentication in HTTP API requests in Golang

In Golang, implementing basic authentication in an HTTP API request is relatively straightforward. Once we construct the request, then we have to call the SetBasicAuth() method and pass username & password package main import ( "fmt" "io/ioutil" "log" "net/http" ) func main() { client := &http.Client{} req, err := http.NewRequest("GET", "http://google.com", nil) if err != nil { log.Fatal(err) } req.SetBasicAuth("admin", "password") resp, err := client.Do(req) if err != nil { log....

February 12, 2023 路 2 min 路 Suraj Narwade