Day 2: Creating Views

We’ve completed a Sinatra web application that provides a basic RESTful API for managing bookmarks. This is a terrific achievement, but it would be even better with a user interface.

Although Sinatra works great for creating a RESTful API, it is not limited in that respect. You can also produce HTML pages quite easily, and that is what we’ll do today. You can choose among many libraries for templating HTML and use them from within Sinatra. We’ll look at three of them: ERB, Mustache, and Slim.

ERB comes with Sinatra and is easy to use. Mustache is an interesting choice if you prefer to have less syntax and no logic in your view templates. Slim is even more concise because it generates HTML tags for you. With these three engines, ...

Get Seven Web Frameworks in Seven Weeks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.