rapid.js icon indicating copy to clipboard operation
rapid.js copied to clipboard

custom route for delete with data. Is it possible?

Open plandem opened this issue 7 years ago • 9 comments

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?

plandem avatar Mar 23 '18 18:03 plandem

Can you provide a code sample please? @plandem

drewjbartlett avatar Mar 28 '18 22:03 drewjbartlett

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.

plandem avatar Mar 28 '18 23:03 plandem

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.

drewjbartlett avatar Mar 29 '18 05:03 drewjbartlett

I asked how to use DELETE and send data same time? By the RFC standard DELETE can have non empty body.

plandem avatar Mar 29 '18 17:03 plandem

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] });

plandem avatar Mar 29 '18 17:03 plandem

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

drewjbartlett avatar Mar 29 '18 17:03 drewjbartlett

Sorry, in my case it will not help, because server expects idList from body :(

plandem avatar Mar 29 '18 17:03 plandem

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 avatar Mar 29 '18 17:03 plandem

@plandem I will have to look into this more at another time. Sorry! Just swamped at the moment!

drewjbartlett avatar Mar 29 '18 18:03 drewjbartlett