1
votes

How does one handle the resource_exists callback in cowboy? After all, to find out whether resource exists - I must query (e.g. database) for resource. But then during the AcceptResource callback (e.g. to_html) I must query for the resource again. Is there any way to prevent this double querying?

Is there any way to preserve that resource for the AcceptResource callback, so that I don't have to pull it form database again?

Reading the cowboy docs, there is flowchart of how a rest request is handled. In it, the callback resource_exists is called first.

1

1 Answers

4
votes

In resource_exists you can add the result of the database query to the State variable that resource_exists returns.

The state is passed as input to the AcceptResource callback where you can use the cached value.