View Categories

REST API

Overview #

The WordPress REST API allows for interaction with the WordPress site from external applications. This section covers how to work with the REST API for the custom cooked_recipe and recipe_category post types provided by this plugin.

Authentication #

To use the WordPress REST API, you need to authenticate your requests. You can use Application Passwords for basic authentication.

Cooked Recipe Endpoint #

/wp-json/wp/v2/cooked_recipe

Creating a New Recipe #

To create a new recipe, send a POST request to the cooked_recipe endpoint with the necessary data.

Example:

curl -X POST https://www.example.com/wp-json/wp/v2/cooked_recipe \
    -u "USERNAME:APPLICATION_PASSWORD" \
    -H "Content-Type: application/json" \
    -d '{
        "title": "My New Recipe",
        "content": "This is the content of the recipe.",
        "status": "publish"
    }'
  • title: The title of the recipe.
  • content: The main content or instructions for the recipe.
  • status: The post status (e.g., publish, draft).

Updating a Recipe #

To update an existing recipe, send a POST request to the specific recipe’s endpoint with the ID.

Example:

curl -X POST https://www.example.com/wp-json/wp/v2/cooked_recipe/RECIPE_ID \
    -u "USERNAME:APPLICATION_PASSWORD" \
    -H "Content-Type: application/json" \
    -d '{
        "title": "Updated Recipe Title",
        "content": "Updated content for the recipe."
    }'

Replace RECIPE_ID with the actual ID of the recipe you want to update.

Deleting a Recipe #

To delete a recipe, send a DELETE request to the recipe’s endpoint with the ID.

curl -X DELETE https://www.example.com/wp-json/wp/v2/cooked_recipe/RECIPE_ID \
    -u "USERNAME:APPLICATION_PASSWORD"

Recipe Category Endpoint #

/wp-json/wp/v2/recipe_category

Creating a New Recipe Category #

To create a new recipe category, use a similar process to creating recipes.

Example:

curl -X POST https://www.example.com/wp-json/wp/v2/recipe_category \
    -u "USERNAME:APPLICATION_PASSWORD" \
    -H "Content-Type: application/json" \
    -d '{
        "name": "Desserts",
        "description": "Category for all dessert recipes."
    }'
  • name: The name of the category.
  • description: A brief description of the category.

Updating a Recipe Category #

To update a category, use the category’s ID in the endpoint.

Example:

curl -X POST https://www.example.com/wp-json/wp/v2/recipe_category/CATEGORY_ID \
    -u "USERNAME:APPLICATION_PASSWORD" \
    -H "Content-Type: application/json" \
    -d '{
        "name": "Updated Category Name",
        "description": "Updated description."
    }'

Deleting a Recipe Category #

To delete a category, use the DELETE method with the category ID.

Example:

curl -X DELETE https://www.example.com/wp-json/wp/v2/recipe_category/CATEGORY_ID \
    -u "USERNAME:APPLICATION_PASSWORD"