0

I am going through REST API GUIDE given by http://www.parse.com

There the doc says about creating objects and storing it in a parse via CURL and Python API calls.

The CURL request for creating object using POST request looks like below:

curl -X POST \
  -H "X-Parse-Application-Id: ${APPLICATION_ID}" \
  -H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' \
  https://api.parse.com/1/classes/GameScore

I wanted to know how can I send request like this using Java.

2
  • Google : How to send HTTP POST in java.... Commented Jul 20, 2015 at 4:32
  • @JunedAhsan using HttpClient ? Commented Jul 20, 2015 at 4:34

2 Answers 2

2

There is a number of Parse.com third-party API libraries:

From https://parse.com/docs/api_libraries

JAVA

  • Almonds — A Java REST API that mimics the Android API.
  • mobile-parse-api — This library implements the REST API of parse.com in java with open interfaces for libgdx and playN.
  • Parse4J — Library for the REST API.
  • ParseFacade — Parse Android SDK alternative.

You might want to evaluate them before making your own interface to parse.com

Sign up to request clarification or add additional context in comments.

1 Comment

You are right. But I am little confused with which one to go for. But I have started with Parse4j. I just wanted to know Can we build API using these set of libraries ?
0

There is one issue in Parse.com Almonds libraries though. there is issue storing Date or other similar complex object structures.

I came across the same issue and fixed Almonds library code to resolve the issue. Now I am able to save Date like any other data type.

replace the toJSONObject() method in ParseObject.java (in Almonds library) with the code below:

// Define the following class level static variables
private static final String DATE_CLASS = "java.util.Date";
private static final String DATA_TYPE = "__type";
private static final String DATA_ISO = "iso";

private JSONObject toJSONObject() {
    JSONObject jo = new JSONObject();

    // TODO - Girish Sharma: Extend this code to save other complex data types
    DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

    Object obj = null;
    try {
        for (String key : mData.keySet()) {
            obj = get(key);

            String className = obj.getClass().getName();

            // Switch over the data types
            if (className == DATE_CLASS) {
                JSONObject dateObj = new JSONObject();
                dateObj.put(DATA_TYPE, "Date");
                dateObj.put(DATA_ISO, formatter.format(obj));
                jo.put(key, dateObj);
            }
            else {
                jo.put(key, obj);
            }
        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return jo;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.