Building Parse Web Apps with the Express Web Framework

Blog-Post-express

Recently we announced Parse Hosting, which allows you to host static content on Parse, and lets your users access it at your favorite *.parseapp.com URL. Many of you asked: What if I want to build a Rails-like web app on Parse? Does Parse support any Node.js web framework? We are here to make that happen.

Today we are announcing support for the Express web framework in Cloud Code. Express is a popular Node.js web framework that can help you build multi-page dynamic web apps quickly. Its features include routing, request body parsing, URL query parsing, cookie handling, HTTP basic auth, and template rendering.

Although you can already build single-page web apps with the Parse JavaScript SDK, Express in Cloud Code enables you to generate dynamic content that can be crawled by search engines, and increase your app’s visibility on the web.

A simple Express app on Parse could look like:

var express = require('express');
var app = express();

// App configuration section
app.set('views', 'cloud/views');  // Folder containing view templates
app.set('view engine', 'ejs');    // Template engine
app.use(express.bodyParser());    // Read the request body into a JS object

// Attach request handlers to routes
app.get('/test', function(req, res) {
  // GET http://example.parseapp.com/test?message=hello
  res.render('test.ejs', { text: req.query.message });  // Render a template
});

app.post('/test', function(req, res) {
  // POST http://example.parseapp.com/test (with request body "message=hello")
  res.json({ message: req.body.message });  // Send a JSON response
});

// Attach the Express app to your Cloud Code
app.listen();

In addition to building web apps, you can also use Express to build custom webhooks on Parse. Previously, you could write Cloud Functions, but calling them required Parse REST API headers and a JSON-formatted request. If you use Express and Parse Hosting, the REST API headers are no longer needed, and you can choose what request format to accept.

Finally, we also implemented a lower-level HTTP API similar to the Node.js HTTP API.  However, we still recommend the Express framework for beginners because of its easy-to-use built-in request processing features.

Before you use Express, you need to download the latest Parse CLI, and set up Parse Hosting with a *.parseapp.com subdomain for your app.

We are here to help you learn about Express. For starters, please see the Cloud Code guide for generating your first Express app.  Then hop over to the Dynamic Web Apps section for more details on what the auto-generated code is doing. For Cloud Code API details, please check out our API documentation for Express and HTTP.

In addition, we’ve built some sample web apps for you to look at:

So try it out and let us know what you think!

Stanley Wang
June 4, 2013
blog comments powered by Disqus

Comments are closed.

Archives

Categories

RSS Feed Follow us Like us