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

Access body in remove() method #1994

Open
ericuldall opened this issue Jun 19, 2020 · 4 comments
Open

Access body in remove() method #1994

ericuldall opened this issue Jun 19, 2020 · 4 comments

Comments

@ericuldall
Copy link

@ericuldall ericuldall commented Jun 19, 2020

Is it possible to access data in a remove() method?

I notice the method accepts (id, params) is it possible to use data?
I have a use case where a DELETE also sends extra meta data about the request for metrics.

Example:

remove (id, data, params) {
  console.log(data.foo);
}
curl -XDELETE -d '{"foo": "bar"}` localhost:3000/{service}/{id}
@ericuldall
Copy link
Author

@ericuldall ericuldall commented Jun 19, 2020

Couldn't find any concrete documentation on this. RFC spec doesn't seem very verbose on the topic and express supports data passed in the DELETE method. So I think it would make sense to allow as much in feathers.

For now I'm doing this:

app.use((req, res, next) => {
  if (req.method === 'DELETE') {
    req.feathers.data = req.body;
  }
});

Then I just access params.data. However it would be nice to keep the api consistent in implementation. I'm interested in what the official position is on this for feathers.

@bwgjoseph
Copy link
Contributor

@bwgjoseph bwgjoseph commented Jun 21, 2020

By default, remove does not need to pass in any body since it's a remove

You can use things like paramsFromClient, paramsForServer to pass things from client to server with additional data. If you would like to get the actual data of the id you are going to remove, you can perform a .get(id) using before hook and you should be able to get the data you want.

@ericuldall
Copy link
Author

@ericuldall ericuldall commented Jun 22, 2020

Hi @bwgjoseph

My question was not whether or not body is required but, if it would be well received to officially support it. As of now, the remove request does not behave similarly to a POST or PUT which allows users to pass data in the body of the request.

Thanks for the reply.

Here's a couple threads on the topic in general:
https://stackoverflow.com/a/10015724/2742481
https://stackoverflow.com/a/299696/2742481

@bwgjoseph
Copy link
Contributor

@bwgjoseph bwgjoseph commented Jun 23, 2020

Hi @ericuldall,

Thanks for the clarification.

For certain use-case, I do certainly agree on supporting body in request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.