0

I am trying to return odata as "nometadata" as listed here: JSON Light for SharePoint

I have set my headers in my factory as follows:

appServices.factory('appItems', ['$resource', function ($resource) {
    return $resource("/_api/web/lists/getbytitle('Todo Task List')/Items", {},
    {
        'query': { method: "GET", isArray: false },
        'update': { method: 'PATCH' },
        'headers': { Accept: 'application/json;odata=nometadata'}
    }
    );
}]);

However, it does not return the nometadata option, but rather defaults to:

Key     Value
Accept  application/json, text/plain, */*

How can I get it to pass in the nometadata option?

Kode
  • 3,073
  • 18
  • 74
  • 140

1 Answers1

1

According to the docs for $resource, the headers object should be placed within an action:

appServices.factory('appItems', ['$resource', function ($resource) {
 return $resource("/_api/web/lists/getbytitle('Todo Task List')/Items", {},
    {
     'query': { method: "GET", isArray: false, headers: { 'Accept': 'application/json;odata=nometadata'} },
     'update': { method: 'PATCH', headers: { 'Accept': 'application/json;odata=nometadata'} },
    }
  );
}]);

As your code stands, headers would become a new action for your resource to be called as: appItems.headers() which wouldn't produce/do what you would expect.

To be honest, the docs aren't completely clear on what type headers: should be or how to set a header globally for all the $resource operations, so you could write your own wrapper around $http if adding/overriding actions becomes tedious.

This answer shows another example

Community
  • 1
  • 1
jsonmurphy
  • 1,600
  • 1
  • 11
  • 19