Skip to content

Commit 1d32ee6

Browse files
authored
Merge pull request #14 from geogeorgiev/master
Fixed custom http method
2 parents 9d835c4 + b3ce9b4 commit 1d32ee6

File tree

6 files changed

+21
-5
lines changed

6 files changed

+21
-5
lines changed

src/actions/Action.js

+11
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,15 @@ export default class Action {
5858
if (config.query) endpoint += `?${Object.keys(config.query).map(k => `${encodeURIComponent(k)}=${encodeURIComponent(config.query[k])}`).join('&')}`;
5959
return endpoint;
6060
}
61+
62+
/**
63+
* Get appropriate methods
64+
* @param {string} type
65+
* @param {object} model
66+
* @param {string} defaultMethod
67+
*/
68+
static getMethod(type, model, defaultMethod) {
69+
const customMethod = model.methodConf.methods[type].http.method;
70+
return (customMethod) ? customMethod : defaultMethod;
71+
}
6172
}

src/actions/Create.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export default class Create extends Action {
1717
const model = context.getModelFromState(state);
1818
const endpoint = Action.transformParams('$create', model, params);
1919
const axios = new Axios(model.methodConf.http);
20-
const request = axios.post(endpoint, params.data);
20+
const method = Action.getMethod('$create', model, 'post');
21+
const request = axios[method](endpoint, params.data);
2122

2223
this.onRequest(commit);
2324
request

src/actions/Delete.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export default class Delete extends Action {
1313
const model = context.getModelFromState(state);
1414
const endpoint = Action.transformParams('$delete', model, params);
1515
const axios = new Axios(model.methodConf.http);
16-
const request = axios.delete(endpoint);
16+
const method = Action.getMethod('$delete', model, 'delete');
17+
const request = axios[method](endpoint);
1718

1819
this.onRequest(model, params);
1920
request

src/actions/Fetch.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export default class Fetch extends Action {
1313
const model = context.getModelFromState(state);
1414
const endpoint = Action.transformParams('$fetch', model, params);
1515
const axios = new Axios(model.methodConf.http);
16-
const request = axios.get(endpoint);
16+
const method = Action.getMethod('$fetch', model, 'get');
17+
const request = axios[method](endpoint);
1718

1819
this.onRequest(commit);
1920
request

src/actions/Get.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export default class Get extends Action {
1313
const model = context.getModelFromState(state);
1414
const endpoint = Action.transformParams('$get', model, params);
1515
const axios = new Axios(model.methodConf.http);
16-
const request = axios.get(endpoint);
16+
const method = Action.getMethod('$get', model, 'get');
17+
const request = axios[method](endpoint);
1718

1819
this.onRequest(commit);
1920
request

src/actions/Update.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export default class Update extends Action {
1818
const model = context.getModelFromState(state);
1919
const endpoint = Action.transformParams('$update', model, params);
2020
const axios = new Axios(model.methodConf.http);
21-
const request = axios.put(endpoint, params.data);
21+
const method = Action.getMethod('$update', model, 'put');
22+
const request = axios[method](endpoint, params.data);
2223

2324
this.onRequest(model, params);
2425
request

0 commit comments

Comments
 (0)