Database Service

Overview

This API service allows clients to interact with a database using various query operations such as Select, Create, and Update. The service utilizes cURL for making HTTP requests and PHP's PDO for database interactions.

Endpoints

Authentication

The API uses Bearer Token authentication. Include the token in the Authorization header of each request.

cURL Request Example

		
curl -X POST \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
	"Credentials": {
		"Username": "your_username",
		"Password": "your_password"
	},
	"Request": "Select",
	"RequestPacket": {
		"Connection_ID": 1,
		"Query_ID": 1,
		"BindParams": {
			":Template_ID": 1
		}
	}
}' \
https://database.thinkinsurance.co.uk/Request.php
		
		

Requesting Page Example

The requesting page script processes incoming requests and interacts with the database service. Here's how it works:

  1. Extract the headers and request packet from the incoming HTTP request.
  2. Include the necessary source files for database connection and query handling.
  3. Check if the requested method exists and is public within the specified class.
  4. If the method exists, execute it with the provided parameters and return the result.
  5. If the method does not exist, return an error message indicating the invalid request.

Options for Select, Update, and Create

For each of the following operations, provide the Request parameter as follows:

JSON Payload Examples

Select Example

			
{
	"Credentials": {
		"Username": "your_username",
		"Password": "your_password"
	},
	"Request": "Select",
	"RequestPacket": {
		"Connection_ID": 1,
		"Query_ID": 1,
		"BindParams": {
			":Template_ID": 1
		}
	}
}
			
		

Create ExampleCreate Example


{
	"Credentials": {
		"Username": "your_username",
		"Password": "your_password"
	},
	"Request": "Create",
	"RequestPacket": {
		"Connection_ID": 2,
		"Query_ID": 2,
		"BindParams": {
			":Template_Name": "New Template",
			":Template_Output": "Template Output"
		}
	}
}
	

Update Example


{
	"Credentials": {
		"Username": "your_username",
		"Password": "your_password"
	},
	"Request": "Update",
	"RequestPacket": {
		"Connection_ID": 3,
		"Query_ID": 3,
		"BindParams": {
			":Template_ID": 1,
			":Template_Name": "Updated Template",
			":Template_Output": "Updated Output"
		}
	}
}
	

Validation Guidelines

When using the API service, adhere to the following guidelines for proper usage: