Custom actions not receiving URL params
See original GitHub issueHi,
I can’t get custom actions on a resource to work correctly. I have the following resources.js
:
import Vue from 'vue'
export var user = Vue.resource('/api/user', {}, {
getCharacters: { method: 'GET', url: '/api/user/characters' }
})
export var character = Vue.resource(null, {}, {
index: { method: 'GET', url: '/api/character' },
search: { method: 'POST', url: '/api/character/search' },
add: { method: 'POST', url: '/api/character' },
verify: { method: 'POST', url: '/api/character{/id}/verify' },
setMain: { method: 'POST', url: '/api/character{/id}/set-main' },
remove: { method: 'DELETE', url: '/api/character{/id}' }
})
I’m importing it in a component and using it like this:
character.setMain({ id: this.character.id }).then(response => {
...
}, (response) => {
...
})
But this results in a request to /api/character/set-main
, whereas it should be /api/character/559460/set-main
. I’ve tried changing the URL structure to place the ID param at the end - same result. Also tried using the example given in the docs:
var customActions = {
foo: {method: 'GET', url: 'someItem/foo{/id}'},
setMain: {method: 'POST', url: 'someItem/bar{/id}'}
}
export var character = Vue.resource('someItem{/id}', {}, customActions)
Same result. This is on vue-resource 1.2.0.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Pass extra parameter to custom actions - Stack Overflow
From the DRF doc of Routing for extra actions. By default, the URL pattern is based on the method name, and the URL...
Read more >Using custom actions with parameters in Amazon QuickSight
A custom action enables you to launch URLs or filter visuals by selecting a data point in a visual or choosing the action...
Read more >Custom Actions for Links to Fields or URLs - Salesforce Help
Custom actions can use field parameters to link to a specific field on a record. Add your field parameters in the custom action...
Read more >Custom Action for a URL Print Page - ServiceMax Help
In the Parameters section at the bottom, create one or more URL parameters. The parameter name cannot contain spaces.
Read more >Create custom parameters for advanced tracking - Google Ads ...
Custom parameters are an advanced type of URL parameter that you can add to ... If you're not familiar with tracking in Google...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found out what was happening @Riari. The actual call should be
It is because if you only pass one parameter in, the resource will threat it like a body object for any method that uses the HTTP verbs POST, PUT, PATCH. Only if you pass two objects in, it will threat the first one as a params object.
I wonder if there is a better approach to this because it seems to me a little confusing, specially when the docs shows a wrong example.
Hi, I get the same issue for my current project. When using post/put method, the ‘id’ param become a request payload. I fix this by add ‘{}’ after the url param, like character.setMain( { id: id }, {} ).then()… try this out.