Playing with API

Screen Shot 2013-10-23 at 9.29.51 PM

I’ve started using API not more than a week ago, and I already fall in love with it. The first thing that hit me was “whoa, no extra work for storing objects in my database” and that’s really it. Saving data was never easier.’s javascript API, the documentation is very good and it will help you to start your project in no time. Beside diving into the details, let me highlight another cool feature of API. It’s the user management. Sign up someone, or let someone sign in, validate their email? Everything is there!

’nuff said, how to start?
Go to, register a new application and copy the application key and javascript key.

Now open your html file, add the’s js library

<script type="text/javascript" src=""></script>

and now initialize your application

Parse.initialize("Application ID", "Javascript Key");

That’s it. Now you are ready to play with the rest of this article.

Sign me up, pronto!
One of the most tedious, boring work while developing an application is to deal with registration, email validation, ACL and taking care of the signing in process. With API this is pretty straight forward. To sign up a new new user, all you gotta do is the following one!

var user = new Parse.User();
user.set("username", "ElMacho");
user.set("password", "chicken");
user.set("email", "");

user.signUp(null, {
  success: function(user) {
    // Everything's done!
  error: function(user, error) {
    alert("Error: " + error.code + " " + error.message);

Your user is signed up! If you need to validate user’s email then log into your dashboard and from your application’s settings section turn on the email validation. It’s simple.

Alright, let me in!
Alright, your users have signed up .Now let them get in. It’s simple to write a sign in script with Parse API

Parse.User.logIn("ElMacho", "chicken", {
  success: function(user) {
  error: function(user, error) {
    console.log("you shall not pass!");

But hey, does an user have to login everytime? No, not at all. The logged in user’s state is saved in browser. So before attempting to sign in him/her again, you can check if he is already logged-in.

var loggedInUser = Parse.User.current();
	//off you go, perform a log in
} else {

easy, eh?

Interesting, how can I deal with data?
Okay, enough with signing up and signing in. Lets save some data. Say, for example, we want to store user’s favorite books in’s datastore. We will also retrieve the list later.

To save some data in, we need to write code like this

var user = Parse.User.current();
var Book = Parse.Object.extend("favoritebooks");
var b1 = new Book({"name":"King Solomon's Mine","user":user});;

var b2 = new Book({"name":"Return of She","user":user});;

While saving an object you can also take care of the error or success state.

var b1 = new Book({"name":"King Solomon's Mine","user":user});, {
		console.log("successfully saved")

You can save as many Books/data as you want, and link them up with the current user. Linking like this is useful for retrieving them in future. As we have a few saved records, lets pull them and see if they are really saved.

var Book = Parse.Object.extend("favoritebooks");
var q = new Parse.Query(Book);
  success: function(results){
    for(i in results){
      var book = results[i];

Once it runs, you can see that it outputs currently logged in user’s favorite books. Pretty neat, eh?

like equalTo, there are a dozen of useful constraints which you can use with your query. You can get the complete list at .’s documentation is pretty solid, and you will find almost everything over there.

It’s dinner time, log me out!
Simple, just call Parse.User.logOut() and you are done!

So is it just about user management and saving data?
No!, not at all!. But saving data and managing credentials + ACL are one of the coolest features that you can do with API. Beside these object storage, you can host your application (ExpressJS based), you can run your code in the cloud (Background Job, Cloud Code), take care of the push notifications and even upload and store binary files.

In overall,’s API is super cool. Give it a try today, you will love it for sure. And by the way, there is a super handy data browser in your application dashboard, use that!

3 thoughts on “Playing with API”

  1. parse is nice, the problem is that they don’t have yet an api library for php, wish they had. I saw a presentation of a dev from facebook on it but really was a bit disappointed that no work on php has been done in this regard.

    1. not maintained by parse/nor facebook “This is a work in progress and is a drasticly different then v1 of this library.” and a wip, but yeah i also saw another one i don’t recall right now

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s