concept Scalaz in category scala

appears as: Scalaz, Scalaz
Scala in Action

This is an excerpt from Manning's book Scala in Action.

Scalaz (pronounced “Scala-zed”) is a library written in the Scala programming language. The idea behind Scalaz is to provide general functions that aren’t provided by the standard Scala API. This section introduces you to the HTTP module that comes with the core Scalaz distribution. And while you’re using the HTTP module, I’ll touch on some of the Scalaz core APIs that are used by the Scalaz HTTP module. Let me first introduce you to the Scalaz HTTP module and how you’ll use it for your weKanban application.

To deploy your web application in Jetty or any Java web container, you have to conform to the Java Servlet API. I mentioned earlier that Scalaz provides a wrapper around Java servlets, so you don’t have to worry about that too much. Figure 6.4 shows how HTTP requests are handled in Scalaz when deployed in a web container.

Figure 6.4. The way HTTP requests are handled by Scalaz

Like a standard Java web application, Scalaz is configured using web.xml. Typically you map all the URLs to any of the subclasses of scalaz.http.servlet.ScalazServlet. In this application you’ll use scalaz.http.servlet.StreamStreamServlet. Usually this servlet is configured with the name of the application class (similar to the Application trait we saw earlier) that will handle all the request and response. You have to write this application class for your weKanban application. The main responsibility of the servlet class is to instantiate the application class and transform between the HTTP servlet request and servlet response to Scalaz’s scalaz.http.request.Request and scalaz.http.response.Response objects.

This application method isn’t that much different from the one I started this discussion with (section 6.4.1). Because you’re using a servlet to handle the HTTP request and response, Scalaz is providing access to the underlying HttpServlet and HttpServletRequest. But for this application we’ll stick to Scalaz Request.