bounswe / bounswe2015group7

Sculture, The Software Project of Future
6 stars 4 forks source link

Using Parse for back-end development #79

Closed fthdgn closed 8 years ago

fthdgn commented 8 years ago

Parse (parse.com) is a good tool for back-end development. We can easily create database and access it via Android application and JavaScript web site. By using Parse, we will decrease the effort to implement the database and API.

If we will use Parse, we should modify some of our database table, because the Parse provides useful things such as Pointers, Arrays etc.

Also I have learnt there is no limitation on String type on Parse. We can use String type for our Story content.

Parse contains built-in login and registration abilities. For other things we can define functions or we can directly access the database. I prefer the first one because it provides more verified access to database.

fthdgn commented 8 years ago

If I understand corrently this is the way of using parse; For example, for creating a story we have created a Object named Story and with fields "content" and "title".

Than we created a Cloud Function like this;

Parse.Cloud.define("createStory", function(request, response) {

    var content = request.params.content;
    var title = request.params.title;

    var StoryClass = Parse.Object.extend("Story");
    var story = new StoryClass();
    story.set("content", content);
    story.set("title", title);
    story.save(null, { success:function(story) {
        response.success(story);
    },
    error:function(error){
        response.error(error);
    }
});
});

We will use this from Android application like this

HashMap<String, String> params = new HashMap<>();
params.put("content", "lfjskfhaskfhs");
params.put("title", "Aj Hhskasd Slj");

ParseCloud.callFunctionInBackground("createStory", params, new FunctionCallback<Object>() {
    @Override
    public void done(Object o, ParseException e) {
        // do something
    }
});

We will use this from Web site javasript like this

Parse.Cloud.run('createStory', {content :'fjakfhkah' , title: 'jfalf'}, {
    success: funtion(result) {
        //do something
    },
    error: function(error){
        //do something
    }]
});