PHP Classes

File: Rules-For-Payload-Formats.md

Recommend this page to a friend!
  Packages of Ramesh Narayan Jangid (Sharma)   Open Swoole Microservices   Rules-For-Payload-Formats.md   Download  
File: Rules-For-Payload-Formats.md
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: Open Swoole Microservices
Implement microservices using Open Swoole
Author: By
Last change: refactor
Date: 5 days ago
Size: 4,016 bytes
 

Contents

Class file image Download

HTTP request Payload

GET request

One can clean the URL by making the required changes in the web server .conf file.

Pagination in GET request

Requires countQuery SQL in the configuration for GET request

defaultPerpage=10
maxResultsPerPage=1000

>One need to urlencode orderBy value

POST, PUT, PATCH, and DELETE request

  • Single
var payload = {
	"key1": "value1",
	"key2": "value2",
	...
};

  • Multiple
var payload = [
	{
		"key1": "value1",
		"key2": "value2",
		...
	},
	{
		"key1": "value1",
		"key2": "value2",
		...
	},
	...
];

HttpRequest Variables

  • $session\['userData'\] Session Data. This remains same for every request and contains key's like id, group\_id, customer\_id
  • $session\['routeParamArr'\] Data passed in URI. Suppose our configured route is /{table:string}/{id:int} and we make an HTTP request for /tableName/1 then $session\['routeParamArr'\] will hold these dynamic values as below.
  • $session\['payload'\] request data. For GET method, the $\_GET is the payload.
  • $session\['__INSERT-IDs__'\] Insert IDs Data as per configuration. >For POST/PUT/PATCH/DELETE we perform both INSERT as well as UPDATE operation. The insertID contains the insert IDs of the executed INSERT queries.
  • $session\['sqlResults'\] Hierarchy data. >For GET method, one can use previous query results if configured to use hierarchy.

Hierarchy Configs

  • Config/Sql/CustomerDB/GET/Category.php >In this file one can confirm how previous select data is used recursively in subQuery select as indicated by useHierarchy flag.
[
	'column' => 'parent_id',
	'fetchFrom' => 'sqlResults',
	'fetchFromData' => 'return:id'
],

  • Config/Sql/CustomerDB/POST/Category.php .Here a request can handle the hierarchy for write operations.
return [
	'__QUERY__' => 'INSERT INTO `category` SET __SET__',
	'__SET__' => [
		'name' => ['payload', 'name'],
		'parent_id' => ['custom', 0],
	],
	'__INSERT-IDs__' => 'category:id',
	'__SUB-QUERY__' => [
		'module1' => [
			'__QUERY__' => 'INSERT INTO `category` SET __SET__',
			'__SET__' => [
				'name' => ['payload', 'subname'],
				'parent_id' => ['__INSERT-IDs__', 'category:id'],
			],
			'__INSERT-IDs__' => 'sub:id',
		]
	],
	'useHierarchy' => true
];

Hierarchy request

  • request - 1: Single object.
var payload = {
	"name":"name",
	"module1": {
		"subname":"subname-value",
	}
}

  • request - 2: Array of module1
var payload = {
	"name":"name",
	"module1":
	[
		{
			"subname":"subname1",
		},
		{
			"subname":"subname2",
		},
		...
	]
}

  • request - 3: Array of payload and arrays of module1
var payload = [
	{
		"name":"name1",
		"module1":
		[
			{
				"subname":"subname1",
			},
			{
				"subname":"subname2",
			},
			...
		]
	},
	{
		"name":"name2",
		"module1":
		[
			{
				"subname":"subname21",
			},
			{
				"subname":"subname22",
			},
			...
		]
	},
	...
]

Contributing

Issues and feature request are welcome.<br /> Feel free to share them on issues page

Author

  • Ramesh N. Jangid (Sharma)

Github: @polygoncoin

License

Copyright © 2026 Ramesh N. Jangid (Sharma).<br /> This project is MIT licensed.