Building a simple web application using Eiffel

Building a simple web application using Eiffel

Today you will learn how to build a “Hello
Web” application written in Eiffel . For this video, you will need to have EiffelStudio
14.11 or greater installed. This project is using the Eiffel Web Framework and in particular the web server foundation library which is used on top of small layer,
called a connector. That layer is used to interact with the web server using any of
the following technologies: CGI, FastCGI, or Nino (the standalone HTTP server written
in Eiffel).. We will be using Nino as it works locally
without having to configure any settings. Also using Nino lets you debug your web application directly in the EiffelStudio debugger. So let’s create a new project. Name it … “hello_web” And we will add two libraries “wsf” and the
“default Nino library” For that we go into project settings, and
we lookup the “wsf library” and add it. Then we need to add the “Nino library.” Because
it does not show up in the list of libraries, we are going to select the “wsf library” and simpy modify the path to the right location of the “Nino library,” which is under: wsf/default/nino-safe.ecf Once this is compiled we can open the root class. Let’s add an inheritance clause to WSF_DEFAULT_SERVICE which turns this application into a web service. And let’s call: “make_and_launch” which is
defined in the new parent we just added. When you compile your changes, you will get an error about a non-implemented deferred feature “execute”. This routine is called each time there is an incoming request and it will actually provide
a response to any incoming HTTP requests. Let’s copy the signature of this routine
into our root class. We will use the response argument to send
a simple response. We will create a simple WSF_PAGE_RESPONSE containing just the “Hello Web” string. By default, Nino listen on the HTTP port,
port 80. Most likely this port is already taken, so you need to change this to a non-used
one if you want to execute your application. Let’s redefine “initialize” in order
to specify another port. We use “set service option” with parameter
“port” and let’s use 9090 We will also enable the verbose output in
the console to see some more details about the execution. After compiling our project, we will set a breakpoint in “execute” to see when we
receive a request from the web server. Now If we go to http://local host:9090 We see that it stops at the break points and that we have access to the requests and the response. By continuing the execution, we see the output
in the web browser: “Hello Web!” This was a simple introduction to EWF. Check
our other videos where you you will learn how to use URL dispatching and other more advance topics of EWF. Thank you for watching!

Danny Hutson

1 thought on “Building a simple web application using Eiffel

Leave a Reply

Your email address will not be published. Required fields are marked *