O Language: HTTP Example Socket

The HTTP socket allows the HTTP protocol to be displayed on the web using any port. You can use the http(path, port, response) function to easily create an http socket.

hello.olm:

def hello = fn(name){
 return "Hello, "+name+"! Welcome to Olang"
}

httptest.ol:

load "hello.olm"
show("Listening 0.0.0.0:8080... Ctrl+C to exit.")
http("/", "8080", hello("Oytun"));

First we loaded our “hello” module with load. Later in the hello() function on the 8080 port to provide this output. When we enter port localhost:8080 from our browser or curl, the result will be;

~> curl localhost:8080
 Hello, Oytun! Welcome to Olang

Now we can display the socket by connecting to 8080 port via HTTP. In the following lessons we will learn how to create routers and render pages on them.