Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the HTTP method to be provided directly #73

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var sync = require("ampersand-sync")
var rawRequest = sync(method, model, options)
```

**method** is a string used for choosing HTTP verb of the sync request. It has to be chosen from the keys of the following map:
**method** is a string used for choosing HTTP verb of the sync request. You can either provide the HTTP method you want to use directly (GET, POST, etc) or specify a RESTful operation which will apply the following convention (used by `ampersand-model`):
```js
{
'create': 'POST',
Expand Down
4 changes: 2 additions & 2 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = function (xhr) {
//Copy the options object. It's using assign instead of clonedeep as an optimization.
//The only object we could expect in options is headers, which is safely transfered below.
var options = assign({},optionsInput);
var type = methodMap[method];
var type = methodMap[method] || method;
var headers = {};

// Default options, unless specified.
Expand Down Expand Up @@ -66,7 +66,7 @@ module.exports = function (xhr) {
}

// Ensure that we have the appropriate request data.
if (options.data == null && model && (method === 'create' || method === 'update' || method === 'patch')) {
if (options.data == null && model && (type === 'POST' || type === 'PUT' || type === 'PATCH')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we already have lodash.includes, would this line be more readable as:

if (options.data == null && model && includes(['POST', 'PUT', 'PATCH'], type)) {

Similarly on L91

params.json = options.attrs || model.toJSON(options);
}

Expand Down