Skip to content

SENATOROVAI/wp-crud-w-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

WP Custom API CRUD

Description

This WordPress plugin enables APIs endpoints to perform CRUD (Create, Read, Update, Delete) operations with a database. It provides a RESTful API to interact with the scientists table in the WordPress database.

API Endpoints

Base URL

http://your-site-url/wp-json/scientists/v1/

GET /scientists

Description: Retrieve a list of scientists from the database.

Usage: This endpoint fetches data from the scientists table.

Example Request:

GET http://your-site-url/wp-json/scientists/v1/scientists

Response:

{
  "status": true,
  "data": [
    {
      "id": 1,
      "first_name": "Ada",
      "last_name": "Lovelace",
      "field_of_study": "Mathematics",
      "birth_year": 1815
    }
    // Other scientists
  ]
}

POST /scientists

Description: Create a new scientist record in the database.

Usage: This endpoint saves a new scientist entry into the scientists table.

Required Parameters:

  • first_name (string): The first name of the scientist.
  • last_name (string): The last name of the scientist.
  • field_of_study (string): The field of study of the scientist.
  • birth_year (integer): The birth year of the scientist.

Example Request:

POST http://your-site-url/wp-json/scientists/v1/scientist
{
  "first_name": "Alan",
  "last_name": "Turing",
  "field_of_study": "Computer Science",
  "birth_year": 1912
}

Response:

{
  "status": true,
  "message": "Scientist added successfully",
  "data": {
    "id": 2,
    "first_name": "Alan",
    "last_name": "Turing",
    "field_of_study": "Computer Science",
    "birth_year": 1912
  }
}

PUT /scientists/{id}

Description: Update an existing scientist record in the database.

Usage: This endpoint updates a scientist entry in the scientists table based on the provided ID.

Required Parameters:

  • id (integer): The ID of the scientist to be updated.
  • first_name (string, optional): The new first name of the scientist.
  • last_name (string, optional): The new last name of the scientist.
  • field_of_study (string, optional): The new field of study of the scientist.
  • birth_year (integer, optional): The new birth year of the scientist.

Example Request:

PUT http://your-site-url/wp-json/scientists/v1/scientist/1
{
  "first_name": "Ada",
  "last_name": "Lovelace",
  "field_of_study": "Computer Science",
  "birth_year": 1815
}

Response:

{
  "status": true,
  "message": "Scientist updated successfully",
  "data": {
    "id": 1,
    "first_name": "Ada",
    "last_name": "Lovelace",
    "field_of_study": "Computer Science",
    "birth_year": 1815
  }
}

DELETE /scientists

Description: Delete a scientist record from the database.

Usage: This endpoint deletes a scientist entry from the scientists table based on the provided parameters.

Required Parameters:

  • first_name (string): The first name of the scientist to be deleted.
  • last_name (string): The last name of the scientist to be deleted.

Example Request:

DELETE http://your-site-url/wp-json/scientists/v1/scientist/int(id)
{
  "first_name": "Ada",
  "last_name": "Lovelace",
}

Response:

{
  "status": true,
  "message": "Scientist deleted successfully"
}

Error Handling

The API will return appropriate error messages in case of issues such as missing parameters or failed operations. Errors are returned in the following format:

{
  "code": "error_code",
  "message": "Error message",
  "data": {
    "status": error_status,
    "params": [
      "list_of_missing_parameters"
    ]
  }
}

Authentication

This API does not include authentication. It is recommended to implement authentication and authorization as needed for your application.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages