![](https://framerusercontent.com/images/Rqpwd4sQ1sVfdb3kOqnCIFylDM.png)
![](https://framerusercontent.com/images/Rqpwd4sQ1sVfdb3kOqnCIFylDM.png)
![](https://framerusercontent.com/images/Rqpwd4sQ1sVfdb3kOqnCIFylDM.png)
Building a Web Server via Golang
Building a Web Server via Golang
Building a Web Server via Golang
Let us build a web server , this implementation is quite interesting.
I have chosen Go language because it has much less compilation time and verbosity( things expressed in less number of words) as compared to any other programming language.
![](https://framerusercontent.com/images/8ATN6cdwNiICxjGPYDmSISpkDU.png)
Golang development has awesome concurrency support , and since it is statically typed language, maximum errors are caught at compilation time.
![](https://framerusercontent.com/images/OoXCQB83lloyZ73NAWR7OkMYgA.png)
We will be developing a web server that can accept GET request and serve a response. Web Server is a program running on any host with an IP (static or dynamic) with a specific port. We will send data (packets) to the server as clients , to which server responds with requested data.
![](https://framerusercontent.com/images/tCrNMhpOvTKVkR9aCF4qrXBPgm0.png)
Web server working
What you must have is Golang installed with compiler and code editor.
We will be using Go-lang package “net” to create HTTP/HTTPS server and make the client requests.(https://golang.org/src/net/net.go)
This package (net) consists of an interface to support network I/O like TCP/IP ,UDP,DNS resolution and emails. We will also be using HTTP package which includes package like ListenAndServe method, which starts the server and listens to incoming requests.
![](https://framerusercontent.com/images/CFRjX3N7ToegmXjykORVNZCKAM.png)
ListenAndServe will accept two arguments:
Address:This is the combination of the IP address and port of the machine in a string format (‘192.168.1.1:2000’).If only port is given in arguments (‘:9000’) , then this port becomes accessible from all the IP addresses across the system.
Handler:This argument is of type Handler interface.Internally this interface uses serveHTTP method , which gets called when ListenAndServe method is executed.
ServeHTTP method: signature for this method is => ServeHTTP(res http.ResponseWriter, req *http.Request) . This will accept the request and returns the response.
![](https://framerusercontent.com/images/XWCgicptZGTj69uTEM6ABmfqom0.png)
Code for Server with request and response
![](https://framerusercontent.com/images/MUUi4FwWkx5qgj18Lgz3clxbm0.png)
Checking for the response from the command line
![](https://framerusercontent.com/images/jGa05jWNBSFxsaxdbCivIvFXJRk.png)
Checking the output in the browser
for checking the code, you can refer this repository:
aniforverizon/Golangserver
You can't perform that action at this time. You signed in with another tab or window. You signed out in another tab or…
github.com
So this was a simple server implementation , now lets customise this by adding a route based control mechanism for requests like (/index.html or /api/myguests or /test) . For this we will be using SeverMux (https://golang.org/pkg/net/http/#ServeMux) structure available in the HTTP package , which will take input as a function for a specific route.
![](https://framerusercontent.com/images/CV2qTDAuXedJhj6qhT8lOejcGkU.png)
Customised route based server implementation
![](https://framerusercontent.com/images/Z17Begz7VJspIXmJRqu4jF7Prk.png)
Output of the customized server
For checking out the code , refer to this repository:
You can't perform that action at this time. You signed in with another tab or window. You signed out in another tab or…
github.com
I will be publishing more Go-lang based simple solutions. For any further Queries or anything related to this article or Golang you can DM me on Linkedin or instagram id=acanubhav94.
Let us build a web server , this implementation is quite interesting.
I have chosen Go language because it has much less compilation time and verbosity( things expressed in less number of words) as compared to any other programming language.
![](https://framerusercontent.com/images/8ATN6cdwNiICxjGPYDmSISpkDU.png)
Golang development has awesome concurrency support , and since it is statically typed language, maximum errors are caught at compilation time.
![](https://framerusercontent.com/images/OoXCQB83lloyZ73NAWR7OkMYgA.png)
We will be developing a web server that can accept GET request and serve a response. Web Server is a program running on any host with an IP (static or dynamic) with a specific port. We will send data (packets) to the server as clients , to which server responds with requested data.
![](https://framerusercontent.com/images/tCrNMhpOvTKVkR9aCF4qrXBPgm0.png)
Web server working
What you must have is Golang installed with compiler and code editor.
We will be using Go-lang package “net” to create HTTP/HTTPS server and make the client requests.(https://golang.org/src/net/net.go)
This package (net) consists of an interface to support network I/O like TCP/IP ,UDP,DNS resolution and emails. We will also be using HTTP package which includes package like ListenAndServe method, which starts the server and listens to incoming requests.
![](https://framerusercontent.com/images/CFRjX3N7ToegmXjykORVNZCKAM.png)
ListenAndServe will accept two arguments:
Address:This is the combination of the IP address and port of the machine in a string format (‘192.168.1.1:2000’).If only port is given in arguments (‘:9000’) , then this port becomes accessible from all the IP addresses across the system.
Handler:This argument is of type Handler interface.Internally this interface uses serveHTTP method , which gets called when ListenAndServe method is executed.
ServeHTTP method: signature for this method is => ServeHTTP(res http.ResponseWriter, req *http.Request) . This will accept the request and returns the response.
![](https://framerusercontent.com/images/XWCgicptZGTj69uTEM6ABmfqom0.png)
Code for Server with request and response
![](https://framerusercontent.com/images/MUUi4FwWkx5qgj18Lgz3clxbm0.png)
Checking for the response from the command line
![](https://framerusercontent.com/images/jGa05jWNBSFxsaxdbCivIvFXJRk.png)
Checking the output in the browser
for checking the code, you can refer this repository:
aniforverizon/Golangserver
You can't perform that action at this time. You signed in with another tab or window. You signed out in another tab or…
github.com
So this was a simple server implementation , now lets customise this by adding a route based control mechanism for requests like (/index.html or /api/myguests or /test) . For this we will be using SeverMux (https://golang.org/pkg/net/http/#ServeMux) structure available in the HTTP package , which will take input as a function for a specific route.
![](https://framerusercontent.com/images/CV2qTDAuXedJhj6qhT8lOejcGkU.png)
Customised route based server implementation
![](https://framerusercontent.com/images/Z17Begz7VJspIXmJRqu4jF7Prk.png)
Output of the customized server
For checking out the code , refer to this repository:
You can't perform that action at this time. You signed in with another tab or window. You signed out in another tab or…
github.com
I will be publishing more Go-lang based simple solutions. For any further Queries or anything related to this article or Golang you can DM me on Linkedin or instagram id=acanubhav94.
Let us build a web server , this implementation is quite interesting.
I have chosen Go language because it has much less compilation time and verbosity( things expressed in less number of words) as compared to any other programming language.
![](https://framerusercontent.com/images/8ATN6cdwNiICxjGPYDmSISpkDU.png)
Golang development has awesome concurrency support , and since it is statically typed language, maximum errors are caught at compilation time.
![](https://framerusercontent.com/images/OoXCQB83lloyZ73NAWR7OkMYgA.png)
We will be developing a web server that can accept GET request and serve a response. Web Server is a program running on any host with an IP (static or dynamic) with a specific port. We will send data (packets) to the server as clients , to which server responds with requested data.
![](https://framerusercontent.com/images/tCrNMhpOvTKVkR9aCF4qrXBPgm0.png)
Web server working
What you must have is Golang installed with compiler and code editor.
We will be using Go-lang package “net” to create HTTP/HTTPS server and make the client requests.(https://golang.org/src/net/net.go)
This package (net) consists of an interface to support network I/O like TCP/IP ,UDP,DNS resolution and emails. We will also be using HTTP package which includes package like ListenAndServe method, which starts the server and listens to incoming requests.
![](https://framerusercontent.com/images/CFRjX3N7ToegmXjykORVNZCKAM.png)
ListenAndServe will accept two arguments:
Address:This is the combination of the IP address and port of the machine in a string format (‘192.168.1.1:2000’).If only port is given in arguments (‘:9000’) , then this port becomes accessible from all the IP addresses across the system.
Handler:This argument is of type Handler interface.Internally this interface uses serveHTTP method , which gets called when ListenAndServe method is executed.
ServeHTTP method: signature for this method is => ServeHTTP(res http.ResponseWriter, req *http.Request) . This will accept the request and returns the response.
![](https://framerusercontent.com/images/XWCgicptZGTj69uTEM6ABmfqom0.png)
Code for Server with request and response
![](https://framerusercontent.com/images/MUUi4FwWkx5qgj18Lgz3clxbm0.png)
Checking for the response from the command line
![](https://framerusercontent.com/images/jGa05jWNBSFxsaxdbCivIvFXJRk.png)
Checking the output in the browser
for checking the code, you can refer this repository:
aniforverizon/Golangserver
You can't perform that action at this time. You signed in with another tab or window. You signed out in another tab or…
github.com
So this was a simple server implementation , now lets customise this by adding a route based control mechanism for requests like (/index.html or /api/myguests or /test) . For this we will be using SeverMux (https://golang.org/pkg/net/http/#ServeMux) structure available in the HTTP package , which will take input as a function for a specific route.
![](https://framerusercontent.com/images/CV2qTDAuXedJhj6qhT8lOejcGkU.png)
Customised route based server implementation
![](https://framerusercontent.com/images/Z17Begz7VJspIXmJRqu4jF7Prk.png)
Output of the customized server
For checking out the code , refer to this repository:
You can't perform that action at this time. You signed in with another tab or window. You signed out in another tab or…
github.com
I will be publishing more Go-lang based simple solutions. For any further Queries or anything related to this article or Golang you can DM me on Linkedin or instagram id=acanubhav94.