What is Mojito?¶
Mojito offers the following features, some of which are discussed in the next section:
- Local development environment and tools (Yahoo independent stack)
- Library for simplifying internationalization & localization
- Integrated unit testing
- Device specific presentation (Hero, Mobile, TV, Web, etc.)
The best way to illustrate why you should use Mojito for creating Web applications is to give an example. Suppose you wanted to create a slideboard application that lets users quickly view news articles from various sources. Your application needs to be available on a variety of devices and use the appropriate UI elements of the device. For example, the application on the Web should provide rich interaction using the mouse, whereas, the application on a tablet or phone should provide the same rich interaction using the touchscreen.
You also want people from all over to be able to use your slideboard application, so you will need to support internationalization and localization. Users should be able to see the application in their local language or choose their preferred language.
In the following, we will discuss how Mojito makes it easier to create the slideboard application.
Views for Different Devices¶
Your slideboard application is a Web application, but we want users to view it on tablets and smart phones as well. Do you create separate versions of your application? Do you write code logic that serves the correct version?
Mojito can identify the calling device by examining the HTTP header User-Agent. You create custom views for different devices, and Mojito will render and serve the correct device-specific views.
Localization and Internationalization¶
Mojito is built on YUI 3, which has an internationalization utility that allows you to handle monolingual and multilingual applications. Using the YUI Internationalization utility and Yahoo Resource Bundles (YRB), your slideboard application could use one language for the UI and serve the content in a different language.
How is it Different?¶
The following sections looks at how Mojito is different from past Web development paradigms. Much thanks goes to Nicholas C. Zakas who wrote the blog post Node.js and the new web front-end from which much of the following content is based on.
Controlling the Back-End UI Layer¶
In the past, applications were often divided into two discrete parts (client/server) that were written by two groups of specialized engineers: front-end and back-end engineers. The front-end engineers wrote the code that was to be executed in the browser, and back-end engineers focused on the business logic and back-end UI layer. By back-end UI layer, we are referring to the payload (templates/data) that is generated by the server.
This diagram reflects the separation of client and server code as well as the back-end UI layer in typical Web application architectures.
In contrast, because Mojito runs on Node.js, the back-end UI layer now lies in the realm of the Mojito application developers, allowing you to control the payload:
Building on an Existing HTTP-Based Service¶
Frameworks such as Rails and Django allow you to connect directly to a database through object-relational mapping (ORM) with no intermediate service layer. With Mojito, you do not directly connect to databases, but instead make HTTP requests to an existing service, thereby, the separating the application code completely from database queries.
Mojito applications can use YQL to make requests to other Web services to get data as well, which gives the application code more control over the requested data, but this again is not a direct database request as YQL is a RESTful proxy that will make HTTP requests to other Web services based on rules defined in XML tables.
This is an important point to remember for those developers who are coming from Rails, Django, and other frameworks that allow you to directly interact with a database. In general, your Mojito applications will need to make HTTP requests to a service that handles database queries or to Web services. You can make HTTP requests with the Y.mojito.lib.REST Class.