custom route for delete with data. Is it possible?
Hi
I tried, but it appends data into the URL. In my case it's not a valid way to call 'delete' api endpoint. How to achieve this - call custom route for delete with data?
Can you provide a code sample please? @plandem
What are you talking about? Only GET and HEAD can't have body, afaik (need to check RFC to be sure, but fetch works in that way). So there is no reason to restrict the DELETE to have a body.
Sorry, not sure I'm following your question. I thought you were asking how to append data but now you're saying it's not valid? Please elaborate a little more if you could so I can understand.
I asked how to use DELETE and send data same time? By the RFC standard DELETE can have non empty body.
const customRoutes = [
{
name: 'user-delete',
url: '/users',
type: 'delete'
},
];
const rapid = new Rapid({ customRoutes });
//this one is not working right now, library sends empty body in case of 'DELETE'
rapid.route('user-delete', null, { idList: [1,2,3,4,5] });
Interesting. This may be a solution for the moment but I think I may want to add better support in v2 which is currently underway.
model.withParam('idList', [1, 2, 3, 4, 5]).route('user-delete') which will generate: api/users?idList%5B0%5D=1&idList%5B1%5D=2&idList%5B2%5D=3&idList%5B3%5D=4&idList%5B4%5D=5
Sorry, in my case it will not help, because server expects idList from body :(
Do you mean library can't do it? Because by RFC standard anything except HEAD and GET can have a body. E.g.: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE
That's why I asked. Had not tried axios directly, maybe there is a problem from the axios side.
@plandem I will have to look into this more at another time. Sorry! Just swamped at the moment!