There’s actually a hook that will fire for all REST API requests. It’s the recommended hook to use when adding your own API endpoints, so you can be sure that this hook will be fired for every single REST API request that your website handles.
/**
* @param \WP_REST_Server $wp_rest_server
*/
function capture_all_rest_api_requests( $wp_rest_server ) {
// Your code here to do your custom REST API handling.
}
add_action( 'rest_api_init', 'capture_all_rest_api_requests' );
Unfortunately you haven’t provided further details as to what exactly you want to do or achieve with this hook, so we can’t be sure this is the most appropriate hook to use.
But you asked for a hook for all incoming requests for the REST API, and this is it.
When this hook is fired, you’ll know it’s a REST API request and nothing else.
Related Posts:
- x-wp-nonce is not allowed by Access-Control-Allow-Headers in preflight response
- WordPress REST API “rest_authentication_errors” doesn’t work external queries?
- Passing a borrowed nonce through Postman fails
- How send get request to external api with username and password
- WP_REMOTE_POST Requests are being blocked by API provider [closed]
- Get all PDF files from page with WordPress API
- “No Access-Control-Allow-Origin header is present” even though it is in the entry file
- Validate rest-api call on create
- Get a remote post ID via API given URL
- How to change the date and time in REST API for comments?
- WordPress HTTP API NTLM Authentication
- [Zapier + WP Webhooks Pro]: Custom Fields get cut off at first comma or semicolon
- REST API and filtering by meta value
- Rest API: trouble receiving response through script (browser and Postman display correctly)
- Is there a way I can fetch the WordPress Developer Code References with an API?
- How to display relations via wordpress Rest API
- How to add Relations of a CCT from JetEngine via WordPress Rest API
- Can I overwrite default WordPress Json API For no more pages text
- Secure WordPress API, how?
- register/login api
- WordPress REST API in Integromat: How to overcome “Sorry, you are not allowed to list users / edit this…”
- how to create JSON array [] for REST response?
- Remove unwanted fields from WP API response
- How to receive JSON payload from a digital device
- The REST API encountered an error in wordpress?
- WordPress API “code”:”rest_no_route” with Custom Route
- Connecting WordPress with an External API
- WordPress single page website redirect to index.html
- Autotrader API Integration
- REST API get featured image source for custom post type
- Update post / page using API + python
- JS WordPress API fetch no response headers
- Issue with API after 6.2 update
- Woocommerce API for calling products by Category ID
- All wp-json routes suddenly return 404
- WordPress – Contact Form 7 – Get uploaded file issue
- API call from searchbar in wordpress
- Looking for a working code example in python for creating a post
- Transmit headers and footers via API from one site to another
- WordPress Error uploading image: 401 API Python Script
- Is the WordPress REST API installed and enabled in a vanilla WordPress 4.7 installation?
- Does something like is_rest() exist
- How to: Make JWT-authenticated requests to the WordPress API
- WordPress Rest API custom endpoint optional param
- Using the Rewrite API to Construct a RESTful URL
- REST API purpose?
- Get post count in wp rest API v2 and get all categories
- WP REST API — How to change HTTP Response status code?
- wp_get_current_user() function not working in Rest API callback function
- How to use WP-REST API to login user and get user data for Android app?
- WP REST API Is it rather easy to rename the default wp-json uri part?
- Query WP REST API v2 by multiple meta keys
- Search WP API using the post title
- check the requesting url
- How would I add custom tables/endpoints to the WP REST API?
- WP REST API Require Password for GET Endpoint
- Displaying a page built with Elementor using the REST API [closed]
- Getting user meta data from WP REST API
- How do I cache (core) API requests?
- WP REST API only returning partial list of users
- Fetch All Posts (Including Those Using a Custom Post Type) With WordPress API
- WP REST API no longer supports filter param, so how do I get posts in a custom taxonomy?
- Understanding SHORTINIT with WordPress 5
- Is there a way to get protected meta fields through any of the available built-in WordPress APIs? (xmlrpc, wp-json)
- How to use _embed when using _fields?
- WP REST API V2 – Retrieve sub page by full slug (URL/Path)
- WP REST API create post authentication issue
- Slow REST API calls on self-hosted WordPress [closed]
- Why is my custom API endpoint not working?
- Is it safe to fix Access-Control-Allow-Origin (CORS origin) errors with a php header directive?
- WordPress REST API validation
- Are there server performance benefits to fetching only specific fields when querying the REST API?
- Retrieving pages with multiple tags using REST API
- How to define a query parameter with REST API?
- Filter posts by multiple custom taxonomy terms using AND operator in REST API v2 (WordPress)
- WP REST API returns blank response if post is too long
- How do I correctly setup an AJAX nonce for WordPress REST API?
- how to authenticate for the REST API from a plugin and from command line
- Why is per_page not working with categories in WP API?
- Increase per_page limit in REST API
- WordPress Rest API: How do we validate with our custom API key?
- Does pre_get_posts affect REST API responses?
- How to feed a HTML5’s EventSource with a REST API custom endpoint?
- WordPress API – Get Drafts
- REST API: How can I restrict a custom post type to only be accessible by authenticated users?
- How do I use the WP REST API plugin and the OAuth Server plugin to allow for registration and login?
- Adding WordPress API Endpoint With Multiple Parameters
- Creating a post with the REST API, curl and oauth returning 401 error
- Retrieve CSS and JS From the REST API
- Using the REST API (v2) javascript client on a private namespaced route
- How to stop WP API endpoint from caching?
- How to Authenticate WP REST API with JWT Authentication using Fetch API
- authentication issue with rest api – rest_cannot_create
- WP REST API core major changes
- WordPress 4.7 REST API endpoints
- Does the REST API (official) support custom post types?
- How to get all posts from parent and children categories?
- wordpress wp-json prefix issue
- How to get the attached gallery in the rest API?
- WP API : date_query parameter