// SPDX-License-Identifier: CC0-1.0
pragmasolidity>=0.8.0;import"./Types.sol";interfaceIRequestMethodTypes{/**
* Requested method type.
* GET, POST, PUT, OPTIONS
*/enumMethodTypes{GET,POST,PUT,OPTIONS}/**
* Response data event.
* @param _response is the response value of the post request or put request.
*/eventResponse(bytes_response);/**
* Get method names based on request method type.
* @param _methodTypes is the request method type.
* @return Method names.
*/functiongetMethods(MethodTypes_methodTypes)externalviewreturns(string[]memory);/**
* Get the data types of request parameters and responses based on the requested method name.
* @param _methodName is the method name.
* @return Data types of request parameters and responses.
*/functiongetMethodReqAndRes(stringmemory_methodName)externalviewreturns(Types.Type[]memory,Types.Type[]memory);/**
* Request the contract to retrieve records.
* @param _methodName is the method name.
* @param _methodReq is the method type.
* @return The response to the get request.
*/functionget(stringmemory_methodName,bytesmemory_methodReq)externalviewreturns(bytesmemory);/**
* Request the contract to create a new record.
* @param _methodName is the method name.
* @param _methodReq is the method type.
* @return The response to the post request.
*/functionpost(stringmemory_methodName,bytesmemory_methodReq)externalpayablereturns(bytesmemory);/**
* Request the contract to update a record.
* @param _methodName is the method name.
* @param _methodReq is the method type.
* @return The response to the put request.
*/functionput(stringmemory_methodName,bytesmemory_methodReq)externalpayablereturns(bytesmemory);/**
* Supported request method types.
* @return Method types.
*/functionoptions()externalreturns(MethodTypes[]memory);}
为了使客户端能够以标准化且可预测的方式操作合约,设置了三种请求方法类型 GET、POST 和 PUT。每种方法的功能都需要在这三种类型中定义,以方便合约调用者理解和处理请求所需的信息。但是,没有 DELETE 操作类型,因为删除合约中的数据是一种低效的操作。开发人员可以自行添加 PUT 请求方法,以将数据设置为有效和无效,并且只在 GET 方法中返回有效数据。