1

I have a working curl call:

curl -X GET \
  -H "X-Parse-Application-Id: XXXX" \
  -H "X-Parse-REST-API-Key: YYYY" \
  -G \
  --data 'where={"number":1}' \
  https://api.parse.com/1/classes/Day

How do I translate this into an angular $http call? I have tried every permutation I can think of, and it still retrieves every Day object. Base on the documentation, I expected the following to work:

    $http({method: 'GET', url: 'https://api.parse.com/1/classes/Day',
        data: {"where": {"number": 1}}});

EDIT: I updated my code to use the Parse JavaScript SDK as recommended in the accepted solution. I installed it using bower:

bower install --save parse

In my app.js I initialize Parse:

Parse.initialize(parseAppId, parseJavascriptKey);

The controller code is a lot more verbose than what I had before, but does work correctly and provides more flexible querying:

  var Day = Parse.Object.extend("Day");
  var query = new Parse.Query(Day);
  query.equalTo("number", currentDay);  // Only retrieve objects matching currentDay
  query.include('challenge,quote');  // Related objects
  query.find({
    success: function(results) {
      console.log("Retrieved object with id: " + results[0].get('id'));
      $scope.day = results[0];
      $scope.$apply();
    },
    error: function(error) {
      console.log(err);
    }
  });
2
  • Should work. Expose WIRe & HEADER logs and see whats there . Compare to what -v or --asci-trace produce on curl calls Commented May 15, 2015 at 23:12
  • It turns out I needed to specify 'params' not 'data'. Commented May 16, 2015 at 0:23

2 Answers 2

2

While Wayne is 100% correct, We have decided to go a bit further and wrote a parse-angular seed project for developing web apps. It can be found here.

After you pulled it, do a npm install

As usual, cloud code should go into cloud/main.js, express code: cloud/app.js angular code: cloud/public/js/

Note that: You will need to change your AppId and AppKey in

config/global.json cloud/public/js/app.js

Then you should have a nice parse-angular project set up and good to go. If there's anything wrong, please feel free to open a pull request. :)

1

Instead of using $http you should be using the parse javascript api instead. https://parse.com/docs/js/guide

2
  • Do you have any specific examples of integrating the parse javascript API into an Ionic (or even plain angularjs) project? I did try integrating the parse-angular-patch module but couldn't figure out how to use it. Commented May 16, 2015 at 0:22
  • No. I have done it though. It's really simple. Just include the javascript file and call Parse.initilize: parse.com/apps/quickstart#parse_data/web/existing.Then in your services you can perform queries. Commented May 16, 2015 at 0:28

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.