Contents
On this page

Toggle Like - Plugixa Recipe

POST /plugixa-recipe/v1/frontend/likes/{recipe_id}

Like a published recipe, or remove the like when the caller already gave one.

Needs any signed-in WordPress user, a subscriber included: a visitor with an account, signed in with the site cookie and nonce or an Application Password.

Request

POST https://your-site.example/wp-json/plugixa-recipe/v1/frontend/likes/12

Path parameters

Name Type Description
recipe_id integer The recipe’s id

Responses

200 OK. data is the like as it now stands.

{
  "success": true,
  "message": "Liked!",
  "data": {
    "is_liked": true,
    "like_count": 10
  }
}
Field Type Meaning
data.is_liked boolean true when this call added the like, false when it removed it
data.like_count integer Likes on the recipe now
message string Liked! or Like removed.

No body. One like per user per recipe.

Errors

Status Code When
404 rest_error No published recipe with that id.
401 rest_forbidden The request is not signed in.

Plus the errors every endpoint can return.

Examples

curl -s -X POST "https://your-site.example/wp-json/plugixa-recipe/v1/frontend/likes/12" \
  -u "jane:$WP_APP_PASSWORD"
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-recipe/v1/frontend/likes/12');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_USERPWD        => 'jane:' . getenv('WP_APP_PASSWORD'),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const auth = 'Basic ' + btoa(`jane:${process.env.WP_APP_PASSWORD}`);
const response = await fetch('https://your-site.example/wp-json/plugixa-recipe/v1/frontend/likes/12', {
  method: 'POST',
  headers: {
    'Authorization': auth,
  },
});
const { data } = await response.json();

Quick Links

Share