-
-
Notifications
You must be signed in to change notification settings - Fork 4
REST API
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.
To use the WordPress REST API, you need to authenticate your requests. You can use Application Passwords for basic authentication.
/wp-json/wp/v2/cooked_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).
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.
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"
/wp-json/wp/v2/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.
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."
}'
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"
- Installation
- Create Recipes
- Shortcodes & Widgets
- Settings
- Plugin Support
- Translations
- Imports
- FAQs
- REST API
- Filters