...

/

A Simple Web Server

A Simple Web Server

This lesson explains how to design a web server that provides services over the web.

We'll cover the following...

Simple web server

HTTP is a higher-level protocol than TCP, and it describes how a web server communicates with client-browsers. Specifically for that purpose, Go has net/http package, which we will now explore.

We will start with some really simple concepts. First, let’s write a Hello world! web server. We import http, and our web server is started with the function http.ListenAndServe("0.0.0.0:3000", nil), which returns nil if everything is OK or an error otherwise (0.0.0.0 can be omitted from the address, 3000 is the chosen port number).

A web-address is represented by the type http.URL, which has a Path field that contains the URL as a string. Client-requests are described by the type http.Request, which has a URL field.

If the request req is a POST of an ...