20.08.15 Faster prototyping with Parse Part of the atmosphere from a meetup organized in July 2015. World is faster than ever. Launching your app or publishing new feature before your competition is crucial. In order to succeed you have to master "Fail fast, build faster" motto. When it comes to building mobile (and web) apps it is hard to think about every single detail before you start coding. Users are in demand, and they are demanding better, simpler, faster ways to do their business. Continuous delivery and fast validation are the keys to success. Agile methodologies are trying to improve software development with processes, plannings, retrospectives etc., but all that fails if your team is just talking agile. If you want to build an agile team, speed up and increase quality of deliveries adding a manager (or anybody) with some Scrum master certification won't do the trick. Your team have to talk, think and act agile. In order to do that you have to know the right tools - Parse platform is one of them. Backend as a service Development of Mobile Backend as a service platforms gained popularity in 2011. Parse was one of the few startups that raised substantial amount of money to develop platforms that will help speed up development of mobile apps. And they did it! Since 2013. he have entire ecosystem of BaaS platforms. Facebook acquired Parse in 2013., probably as an answer to Google's and Microsoft's BaaS solution. Today we have big and small players in this field, offering pretty much the same stuff. Selecting BaaS is like selecting development language - it all depends from your preferences, needs and abilities. How does parse make us faster Parse, same as most of all other BaaS platforms, offers set of features which are answers to mobile developers prayers. Data storage Offline caching User management Push Notification Social integration Analytics On-demand scaling Cloud code (easy way to write your server code) All those tedious features for which you need to wait (sometimes beg) your backend team to develop are available through simple SDK. If you want to get an inside looks on how it works, you can take a look at the code - Parse SDK is open source. Available for platform of your choosing. Getting started with parse You need less than 10 minutes to setup everything you need to use parse. Here is how you start: Create account and app Download SDK Download seed project Check your app key and secret Initialize your SDK (with your key and secret) Basically, just go to Parse.com and follow the quickstart quide, but make sure you come back and finish reading this article. User management What if I told you that you can setup user signup, signin, social logins, email confirmation and reset password features in under an hour, and for another hour you can set up welcome emails, user roles and your own access control list. It is true. Parse offers elegant user management that you can integrate in your app. This has much more significance if you are making some kind of a game and user management and score board is all you need from backend. Parse SDK has ParseUser class and most of the methods you need to handle users are in it. Methods like: Sign up in background Login in background Get current (logged in) user. Logout Request password reset in background Of course all methods that run in background have their on main thread version (if you need one, but I don't see why). ParseUser has email, username and password attributes. You can add your own attributes (like phone number, photo, first and last name etc.). All Parse objects including ParseUser act like JSON object, meaning - you can define attributes by simply putting key-value pairs in object. Take a look at the code snippet. ParseUser user = new ParseUser(); user.setUsername("someusrname"); user.setPassword("somepassword"); //will be encrypted user.setEmail("email@example.com"); user.put("whateverId","someValue"); You can define attributes from the client side and this will automatically add new columns to your table definitions on Parse portal. One thing that you need to keep in mind is that email, username and password are default attributes of ParseUser if you add your own attributes you will have to make another call to fetch (if needed) all those attributes. Data If you are not making a game, but a simple app you will find really cool benefits in Parse Data features. With parse you have your remote DB (Parse is using MongoDB under the hood) ready to go, just visit data section of Parse portal and define your tables. Columns you can add from the app (as you add some row for the first time) or via portal. You can also define relations between entities. Parse supports: One to many (using Pointers and Arrays) Many to many (using Relations or Join tables) One to one (good for limiting visibility of some data or splitting the data due to size) Parse object has maximum size of 128K so if you have object larger than that you will have to split it. This of course is not valid for images or files, you have special ParseFile object for that use. The most common use case of ParseFile is storing images but you can also use it for documents, videos, music, and any other binary data (up to 10 megabytes). Accessing the data Accessing the data from your cloud DB is fairly easy. It's done via Parse queries. With queries you can setup queries similar to queries you are used to write with your regular DBs. Take a look at one query sample: ParseQuery<ParseObject> query = ParseQuery.getQuery("Task"); query.whereEqualTo("title", "SomeTitle"); query.findInBackground(new FindCallback<ParseObject>() { public void done(List<ParseObject> taskList, ParseException e) { if (e == null) { Log.d("tasks", "Retrieved " + taskList.size() + " tasks"); } else { Log.d("tasks", "Error: " + e.getMessage()); } } }); Cloud Code If you need backend with more features, not just simple data storage, you can write your own cloud code. Cloud code is JavaScript code which you can write on server side in order to achieve additional data processing or processing. Things that you need to know about cloud code: Simple cloud code Advanced cloud code Cloud code model Simple could code provides you with an easy way to add your custom code after/before something is saved/deleted from your tables. You can also write your own cloud functions. Advanced cloud code provides you with networking that you allows sending HTTP requests to any HTTP Server using Parse.Cloud.httpRequest. This function takes an options object to configure the call. There is a limit of 8 concurrent http requests per Cloud Code request, and additional requests will be queued up. You can use Webhooks to write your server-side logic in your own environment with any tools you wish to use. This can be useful if you want to use a language other than JavaScript or if you require a specialized library or technology not available in Cloud Code. Parse also allows you to set up jobs that run in the background. Background Jobs are useful for long running tasks such as integrating with external sites where the response time could be slow, or sending out batched push notifications. Cloud Modules are the easiest way to integrate your Parse app with third-party services and libraries. Parse hase few predefined modules like: Mailgun Mandrill Moment Parse Image SendGrid Stripe Twilio Underscore But you can add your own modules. This is huge help, because now you can add powerful APIs to your app in few simple steps. Push notifications If you want to start using push, start by completing the tutorials for iOS and/or Android. You will have to submit app and client keys, certificates and other settings needed for notifications. But after completing the push notification setup guide you will be able to send notification in just few lines of cloud code. Parse.Push.send({ where: query, // Set our Installation query data: { alert: "A test notification from Parse!" } }); FAQ Instead of a conclusion I've decided to write some frequent Q&A that I’ve collected on some of my talks about Parse. How can Parse speed up my prototype? By using Parse feature you are saving time, but you are also saving effort of your team. Can I use Parse in production? Yes you can. There is a huge list of Parse clients on their site. It’s just the matter of budgeting and figuring out if Parse has everything you need. How can I move from parse? Try to isolate app code that uses parse features by providing your own wrappers. In that way you will be able to quickly move from Parse to your own APIs. Is parse free? There is a free plan (see details). For additional capabilities you are required to purchase paid account. How much can I get with free plan? 30 requests per second, 1 background job, 20GB of file storage and 20 GB of DB storage with 2TB of file transfer. If you plan your app right keep number of request on minimum (not just for parse but because you should always think about users data plan) free plan can get you far enough. How do I manage cloud code? You write your code in JavaScript and you push it to Parse portal via command line, you can use whatever source code control you like to keep track on changes of your cloud code. What is downside of prototyping with Parse? Downside is that you are dependent on Parse platform and SDKs (if you use them). If you don't develop with plan to move to some other platform (your own) it could be hard to move from Parse. Also Parse has some limitations in terms of queries (there is no group by for example). Speed is also in question. Because you are not in control there is not so much you can do if you need some optimization on lower level. Be smart, there is no silver bullets - just tools fit for a task. Know your tools, evaluate your requirements and act accordingly. Autor: Goran Djonovic