Maybe start with just GET
. Your route looks weird as well. Try just:
register_rest_route('my-project/v1', '/action/', [
'methods' => WP_REST_Server::READABLE,
'callback' => 'api_method',
]);
And your callback is not returning a valid response. Let your callback look more like this:
$data = [ 'foo' => 'bar' ];
$response = new WP_REST_Response($data, 200);
// Set headers.
$response->set_headers([ 'Cache-Control' => 'must-revalidate, no-cache, no-store, private' ]);
return $response;
Finally you must combine wp-json
, the namespace my-project/v1
and your route action
to the URL you now can check for what you get:
https://my-domain.local/wp-json/my-project/v1/action
Related Posts:
- WordPress 4.7 REST API endpoints
- Can I define multiple callback methods depending on the call method?
- Query the REST API for a Tag by slug
- Rest API Custom Endpoint with space character
- Is there anyway to format my EndPoint URL in WordPress?
- Custom Rest API POST endpoint with conditionally required parameters
- How to force JWT auth for default GET endpoints of WordPress rest api?
- WordPress Rest API custom endpoint for RSS feed
- Custom endpoint to get all custom taxonomy terms
- What’s the right way to validate JSON data coming from an AJAX POST request?
- How can I secure my custom rest api endpoint or add under a already existing rest group
- Securing REST API wp-json/wp/v2/users endpoint
- Delete row from table using custom endpoint via API
- Custom rest api endpoint response json problem
- Is the WordPress REST API installed and enabled in a vanilla WordPress 4.7 installation?
- WordPress Rest API custom endpoint optional param
- check the requesting url
- WP REST API Require Password for GET Endpoint
- WP REST API V2 – Retrieve sub page by full slug (URL/Path)
- Filter posts by multiple custom taxonomy terms using AND operator in REST API v2 (WordPress)
- WP REST API core major changes
- How to get all posts from parent and children categories?
- How to force Authentication on REST API for Password protected page using custom table and fetch() without Plugin
- Match REST API post output from custom endpoint
- Attach featured image to custom endpoints
- WordPress: How to create custom REST API route?
- REST API URL parameters not working with apache server
- How to Pull ALL Posts, Categories, or Tags in WordPress REST API
- WordPress REST API “rest_authentication_errors” doesn’t work external queries?
- apiFetch security
- Application Password is not enable by default?
- Cannot get ‘sanitize_callback’ to work for rest parameters
- Using pre_get_posts, how to target the REST API, only?
- How to use current_user_can() in register_rest_route()?
- WP Rest endpoint with custom post type and ACF Fields
- How to block all REST API endpoint except which I wrote custom?
- Authentication with internal WP_REST_Request and rest_do_request()
- WP REST API GET Requests require authentication
- What’s the “?P” register rest api construct, what is for and where to find official docs?
- WordPress REST API json – How to activate gzip compression?
- Does it still make sense using json endpoint ep_mask now that there’s the new rest api? [closed]
- WP Remote Request not returning all of content via request
- Cannot DIsplay a Snackbar Notice on Button Click – Notice is undefined
- WordPress custom endpoint returning blank response
- How to add a custom REST field to limit data when fetching?
- WordPress JSON data to and from database to be shown on rest point
- REST API: best place to set current user for JWT auth?
- rest api request including meta_query filter
- WP_REST_Response() doesn’t seem to return the expected object
- Setting ?context=edit results in rest_forbidden_context, even for an Administrator user
- Rest API: wp_verify_nonce() fails despite receiving correct nonce value
- Update user meta via REST API?
- WP Rest Api- Update callback (POST request) to existing database table through the rest api
- Save default options as an array of options and display in REST API
- Get a term object using getEntityRecords
- WordPress REST Api get posts by ID
- [Zapier + WP Webhooks Pro]: Custom Fields get cut off at first comma or semicolon
- Which route in the WP REST API do I access data passed into register_setting()?
- How to use Python to create a Post in WordPress?
- REST Endpoint API 404
- Send a get request to wordpress
- How to set up the REST API to refer to media on a CDN
- Best Authetication between REST API and Mobile App
- Replace content via rest api only?
- WP rest api endpoint protection using jwt token
- WP Rest API – Change response status code for failed validation request
- Unable to create a Rest end-point
- Log in user using WordPress REST API
- Rest API Paginate until all posts are imported
- Can i fetch the list of pouplar posts of last 24 hours from WordPress API?
- WordPress Rest Api rest_cannot_edit
- how to create JSON array [] for REST response?
- Getting 401 unauthenticated error in WP Rest API revisions
- How to receive JSON payload from a digital device
- WordPress Custom Rest Api – How to get Image Url?
- Remote publishing using WP’s RetAPI // Issues with HTACCESS
- save_post hook error with REST API
- Connecting WordPress with an External API
- rest api add post meta
- Users REST API not working?
- Using WordPress solely as a Backend – dealing with WP_SITEURL
- use WordPress Rest API to build a web application
- REST Request Post including meta/custom fields
- Display Post Featured Image along with Categories via WP Rest API
- Register rest field authentication with REST API
- Why wp_set_password not working within a api endpoint?
- WordPress api returns distinct data
- Redefine REST API variables
- Where is the HTML content for my post in the API
- Using WordPress.com API to retrieve featured images
- WordPress Rest API Escapes Returned URLs Forward Slash
- Update post / page using API + python
- Calling a Rest API with parameters on button Click
- How to cache WordPress oembed links in the page header?
- REST API – Authentication/Logon security
- WordPress json – How to use the content rendered from json
- Subscriber role cann’t add comment meta using REST API
- WordPress REST API function not calling from external site
- Issue with API after 6.2 update
- Verify user login and password over api