Chapter 7. Server-side templating
This chapter covers
- Deciding whether server-side templating is right for you
- Introducing Scalate
- Serving content with Scalate
- Comparing Scalate and Twirl
In chapters 5 and 6, you saw how Scalatra can be used to build RESTful APIs by returning JSON and files directly from your controller actions. Scalatra excels at this architecture, but as an HTTP framework, it’s also well suited to serving websites. In this chapter, we’ll discuss what this means and look at how Scalatra can integrate various standalone templating systems to render the user interface.
Server-side templating will be a familiar topic to many readers. Many Scalatra users come from the Java world, where JSP and JavaServer Faces (JSF) are used to render websites. Others come from Ruby’s Sinatra, which boasts integration with 20 templating systems.
Server-side templates have also been stigmatized as an outmoded design. The rise of web APIs has certainly led to some movement away from the technique. Still, there are certain types of Scalatra applications where they remain a great fit. Let’s first examine whether server-side templates are right for you.
The distinction between websites and web applications is a bit fuzzy, but it’s a topic worth considering as you build your architecture around Scalatra.