O Language: First Router

The router socket structure was created with the intention of creating an API over the HTTP/S protocol and exchanging data through the socket. In web based projects it is possible to write web server quickly and easily. In addition, the API can be created in micro-services.

hello.olm (as hello module):

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

router.ola (as router script):

load "hello.olm"

def config = {
 "GET" : {
 "/" : "Welcome to the O-Lang Router!"
 },
 "POST":{
 "/:name" : hello("{{.name}}")
 }
}

show("Listening 0.0.0.0:8080... Ctrl+C to exit.")
router("8080", config);

GET method test:

~> curl -X GET localhost:8080
Welcome to the O-Lang Router!

POST method test (oytun as parameter value for name [ :name => {{.name}} ]):

~> curl -X POST localhost:8080/oytun
Hello, oytun! Welcome to Olang

As you can see in the example, we wrote a web micro service using port 8080 via get and post methods.