Rationale
Type of request method
In order to enable the client to operate the contract in a standardized and predictable way, three request method typesGET, POST, and PUT are set. The functions of each need to be defined in these three types to facilitate the contract caller to understand and process the information required for the request. However, there is no DELETE operation type because deleting data in the contract is an inefficient operation. Developers can add a PUT request method by themselves to set the data to be valid and invalid, and only return valid data in the GET method.
Request method parameter type
Some functions are defined in each request method type. They all include request parameter data type and response parameter data type, which need to be set in theconstructor and then obtained according to the method name through getMethodReqAndRes. The data type of the parameter is defined by the enumeration of the data type. When processing the request parameter, abi.decode is used to decode according to the request parameter type and the request value. When returning the response, abi.encode is used to encode according to the response value and the response parameter type. In addition, we can get the method usage instructions by calling getMethodInstruction.
Interface
IComponent.sol
Types.sol contains an enumeration of Solidity types used in the above interfaces.
Types.sol
Specifications
getMethodsGet method names based on request method type.getMethodReqAndResGet the data types of request parameters and return parameters based on the requested method name.getMethodInstructionGet the instruction of method.getRequest the contract to retrieve records.postRequest the contract to create a new record.putRequest the contract to update a record.optionsSupported request method types.
methodRequests and methodResponses are used to define the request parameter type and response data type of Method. Types.sol is a data type Library, which contains all data types of solidity.
methods is used to store the method name array of each request type.
instructions is used to store method instructions
options function will return the request method type supported by the component.
setMethod is used to set the request parameter type and response data type of the method.
getMethods returns the response method names according to the request type.
getMethodReqAndRes is used to obtain the request parameter type and response value type of the method based on the method name.
getMethodInstruction is used to query the usage of method.
get, post, and put .
Workflow

1
options
Call 
options to obtain supported request method types.2
getMethods
Call 
getMethods to obtain the request method name.3
getMethodInstruction
Call 
getMethodInstruction to obtain the request method instruction.4
getMethodReqAndRes
Call 
getMethodReqAndRes to obtain the request parameter data type and response value data type.5
Encode
Encode request parameters and call 
get, post, and put.6
Decode
Decode response value.

