Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

$resource HTTP method must be uppercase string (POST vs post) #1403

Closed
dustinmartin opened this issue Sep 21, 2012 · 2 comments
Closed

$resource HTTP method must be uppercase string (POST vs post) #1403

dustinmartin opened this issue Sep 21, 2012 · 2 comments

Comments

@dustinmartin
Copy link

When defining a resource, if you do not have the HTTP method in uppercase (POST vs post) it doesn't work properly but doesn't throw any errors letting you know of a problem.

Here is an example resource definition:

var Project = $resource("api/projects.cfm/:projectID",
    { "projectID": "@projectID" },
    { "query": { method: "GET", isArray: true },
      "get": { method: "GET" },
      "save": { method: "POST" },  // Problems caused if 'POST' is changed to 'post'
      "destroy": { method: "DELETE" } }
);

If I change 'POST' to 'post' a couple things happen.

1.) Any params not defined in the paramDefaults object seem to be ignored completely.

2.) All params are only ever sent as a URL query string.

Since case matters, I think a change should be made in Angular to auto uppercase the HTTP method or throw an error to let the developer know of a problem. At the very least, if no changes is going to be made, the docs should explain this.

@deviousdodo
Copy link
Contributor

I made a spec and a fix for this, but then the [docs|http://docs.angularjs.org/api/ngResource.$resource] do say:

method – {string} – HTTP request method. Valid methods are: GET, POST, PUT, DELETE, and JSONP

If it's still interesting to anyone I can make a pull request with the fix.

@dustinmartin
Copy link
Author

Although the docs mention the valid methods, Angular does not throw any errors if an invalid method like 'post' or 'ABC' is used. It seems that there should be validation there.

Without explicitly mentioning that the method must be uppercase it is easy to make the assumption that 'POST' and 'post' are the same. Especially considering that jQuery allows either and many people will have used jQuery prior to Angular.

pkozlowski-opensource pushed a commit that referenced this issue Nov 30, 2012
Perform call `angular.uppercase` on all given action methods.

Closes #1403
jbdeboer pushed a commit to jbdeboer/angular.js that referenced this issue Feb 9, 2013
Perform call `angular.uppercase` on all given action methods.

Closes angular#1403
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants