0

I have a REST server that takes a query string in the request body of a GET statement.

It's similar to the Parse REST api that does the same. As seen in the curl statement below.

curl -X GET \
  -H "X-Parse-Application-Id: ${APPLICATION_ID}" \
  -H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
  -G \
  --data-urlencode 'where={"playerName":"Sean Plott","cheatMode":false}' \
  https://api.parse.com/1/classes/GameScore

My question is: How do I send a Backbone fetch (essentially a -X GET) with a data string.

Ive tried the following;

   fetch: function(options) {
      options = _.extend({data: 'Active is true' }, options);
      return Backbone.Collection.prototype.fetch.apply(this, arguments);
  }

Currently, that appends the string on the URL as parameters as such

http://restserver.com/collection/Customer?Active%20eq%20true

Gabe Rainbow
  • 3,658
  • 4
  • 32
  • 42

1 Answers1

0

In your collection class, implement the url property as a function that returns the URL path plus the query string you want. The query string can be built up from properties stored on your collection instance like collection.playerName, etc. This pattern works well for a search query string type use case such as yours.

Peter Lyons
  • 142,938
  • 30
  • 279
  • 274