wp-rest-api-log icon indicating copy to clipboard operation
wp-rest-api-log copied to clipboard

create documentation and examples of logging custom inbound requests

Open petenelson opened this issue 9 years ago • 8 comments

for handling inbound web/API calls that are not handled via the WP REST API

petenelson avatar Jul 07 '15 17:07 petenelson

Hello,

I am interested in using this plugin. For this issue, is it already implemented or does it needs to be implemented? If it needs to be implemented, then perhaps I can be of help :)

swashata avatar Mar 25 '16 10:03 swashata

It needs to be implemented, but it should probably wait until beta 2 is released in the near future as it may have some updates to the actions and filters used for logging requests.

petenelson avatar Mar 25 '16 13:03 petenelson

I checked with the beta 1 version and it logged a custom request on URL /wp-json/ipt-api/v1/fsqm/ (This is just something I have developed for my envato plugins). So I think I was confused with the topic. You are probably talking about custom REST API implementation that doesn't do a register_rest_route ?

swashata avatar Mar 25 '16 18:03 swashata

Yeah, it technically has the ability to log requests that aren't going through the core REST API functions. For example, say you were doing a wp_remote_get() from your server to another server, you could manually log the request and response by doing do_action( 'wp-rest-api-log-insert', $args ) and passing it an array of data in the expected format. The source code has more details: https://github.com/petenelson/wp-rest-api-log/blob/master/includes/class-wp-rest-api-log.php#L37

Thinking about this more, I'll probably want to pass some sort of context (probably a taxonomy) as to where the request/response came from... whether it's from the REST API or something logged outside of the REST API.

petenelson avatar Mar 25 '16 20:03 petenelson

I got it. So this system has the ability to log both inbound and outbound requests.

Also I see that the logging happens through the post table and custom post type. Any particular reason behind using this approach? Would it not had been better to use a different table? (In terms of performance, not jamming up the post table etc).

swashata avatar Mar 26 '16 15:03 swashata

The version in the WordPress repo uses custom tables, but this beta version moves away from those into the posts table. Performance is a concern, but it was easier to use WP_Query to get records vs writing tons of custom SQL statements to search for records. I'll be adding an automatic process to purge old log records to hopefully keep down the impact on the posts table, as well as an admin settings page to be able to turn logging on and off as-needed.

petenelson avatar Mar 26 '16 16:03 petenelson

May I confirm that if I using this https://www.npmjs.com/package/wordpress to push to wordpress also won't be log?

shiroamada avatar Mar 31 '17 13:03 shiroamada

@shiroamada looks like that uses XML RPC, which would not be logged by the REST API Log plugin.

petenelson avatar Mar 31 '17 16:03 petenelson