WebFioriAPI ReferenceLearnDownloadContributeLearn{{result.parent_page}} > {{result.title}}{{result.title}}Classes{{result.class_name}}{{result.summary}}Methods{{result.name}}{{result.summary}}

namespace \webfiori\http

abstract class AbstractWebService

Class Attributes Summary

const EA constant which is used to indicate that the message that will be sent is of type error.const IA constant which is used to indicate that the message that will be sent is of type info.const METHODSAn array that contains the names of request methods.

Class Methods Summary

public function &getRequestMethods()Returns an array that contains all possible requests methods at which the service can be called with.public function __construct(string$name)Creates new instance of the class.public function __toString()public function addParameter(RequestParameter|array$param)Adds new request parameter to the service.public function addParameters(array$params)Adds multiple parameters to the web service in one batch.public function getAuthHeader()Returns an array that contains the value of the header 'authorization'.public function getInputs()Returns an associative array or an object of type Json of filtered request inputs.public function getManager()public function getParamVal(string$paramName)Returns the value of request parameter given its name.public function hasParameter(string$name)Checks if the service has a specific request parameter given its name.public function isAuthRequred()Returns the value of the property 'requreAuth'.public function isAuthorized()Checks if the client is authorized to use the service or not.abstract function processRequest()Process client's request.public function removeParameter(string$paramName)Removes a request parameter from the service given its name.public function removeRequestMethod(string$method)Removes a request method from the previously added ones.public function send(string$conentType, mixed$data, int$code)Sends Back a data using specific content type and specific response code.public function sendResponse(string$message, string$type, int$code, mixed$otherInfo)Sends a JSON response to the client.public function setIsAuthRequred(boolean$bool)Sets the value of the property 'requreAuth'.public function setManager(WebServicesManager|null$manager)Associate the web service with a manager.public function toJSON()Returns a Json object that represents the service.

Class Attributes Details

const EA constant which is used to indicate that the message that will be sent is of type error. const IA constant which is used to indicate that the message that will be sent is of type info. const METHODSAn array that contains the names of request methods. This array contains the following strings:
  • GET
  • HEAD
  • POST
  • PUT
  • DELETE
  • TRACE
  • OPTIONS
  • PATCH
  • CONNECT

Class Methods Details

public function &getRequestMethods()Returns an array that contains all possible requests methods at which the service can be called with. The array will contains strings like 'GET' or 'POST'. If no request methods where added, the array will be empty.Returns: arrayAn array that contains all possible requests methods at which the service can be called using.public function __construct(string$name)
Creates new instance of the class. The developer can supply an optional service name. A valid service name must follow the following rules:
  • It can contain the letters [A-Z] and [a-z].
  • It can contain the numbers [0-9].
  • It can have the character '-' and the character '_'.
If The given name is invalid, the name of the service will be set to 'new-service'.

Parameters:

  • string $name The name of the web service.
public function __toString()Returns: string public function addParameter(RequestParameter|array$param)Adds new request parameter to the service. The parameter will only be added if no parameter which has the same name as the given one is added before.

Parameters:

  • RequestParameter|array $param The parameter that will be added. It can be an object of type 'RequestParameter' or an associative array of options. The array can have the following indices:
    • name: The name of the parameter. It must be provided.
    • type: The datatype of the parameter. If not provided, 'string' is used.
    • optional: A boolean. If set to true, it means the parameter is optional. If not provided, 'false' is used.
    • min: Minimum value of the parameter. Applicable only for numeric types.
    • max: Maximum value of the parameter. Applicable only for numeric types.
    • allow-empty: A boolean. If the type of the parameter is string or string-like type and this is set to true, then empty strings will be allowed. If not provided, 'false' is used.
    • custom-filter: A PHP function that can be used to filter the parameter even further
    • default: An optional default value to use if the parameter is not provided and is optional.
    • description: The description of the attribute.
Returns: booleanIf the given request parameter is added, the method will return true. If it was not added for any reason, the method will return false.
public function addParameters(array$params)Adds multiple parameters to the web service in one batch.

Parameters:

  • array $params An associative or indexed array. If the array is indexed, each index should hold an object of type 'RequestParameter'. If it is associative, then the key will represent the name of the web service and the value of the key should be a sub-associative array that holds parameter options.
public function getAuthHeader()Returns an array that contains the value of the header 'authorization'. Returns: arrayThe array will have two indices, the first one with name 'scheme' and the second one with name 'credentials'. The index 'scheme' will contain the name of the scheme which is used to authenticate ('Basic', 'Bearer', 'Digest', etc...). The index 'credentials' will contain the credentials which can be used to authenticate the client.public function getInputs()Returns an associative array or an object of type Json of filtered request inputs. The indices of the array will represent request parameters and the values of each index will represent the value which was set in request body. The values will be filtered and might not be exactly the same as the values passed in request body. Note that if a parameter is optional and not provided in request body, its value will be set to 'null'. Note that if request content type is 'application/json', only basic filtering will be applied. Also, parameters in this case don't apply.Returns: array|Json|nullAn array of filtered request inputs. This also can be an object of type 'Json' if request content type was 'application/json'. If no manager was associated with the service, the method will return null.public function getManager()Returns: WebServicesManager|null public function getParamVal(string$paramName)Returns the value of request parameter given its name.

Parameters:

  • string $paramName The name of request parameter as specified when it was added to the service.
Returns: mixed|nullIf the parameter is found and its value is set, the method will return its value. Other than that, the method will return null. For optional parameters, if a default value is set for it, the method will return that value.
public function hasParameter(string$name)Checks if the service has a specific request parameter given its name. Note that the name of the parameter is case sensitive. This means that 'get-profile' is not the same as 'Get-Profile'.

Parameters:

  • string $name The name of the parameter.
Returns: booleanIf a request parameter which has the given name is added to the service, the method will return true. Otherwise, the method will return false.
public function isAuthRequred()Returns the value of the property 'requreAuth'. The property is used to tell if the authorization step will be skipped or not when the service is called.Returns: booleanThe method will return true if authorization step required. False if the authorization step will be skipped. Default return value is true.public function isAuthorized()Checks if the client is authorized to use the service or not. The developer should implement this method in a way it returns a boolean. If the method returns true, it means the client is allowed to use the service. If the method returns false, then he is not authorized and a 401 error code will be sent back. If the method returned nothing, then it means the user is authorized to call the API. If WebFiori framework is used, it is possible to perform the functionality of this method using middleware.abstract function processRequest()Process client's request. This method must be implemented in a way it sends back a response after processing the request.public function removeParameter(string$paramName)Removes a request parameter from the service given its name.

Parameters:

  • string $paramName The name of the parameter (case sensitive).
Returns: null|RequestParameterIf a parameter which has the given name was removed, the method will return an object of type 'RequestParameter' that represents the removed parameter. If nothing is removed, the method will return null.
public function removeRequestMethod(string$method)Removes a request method from the previously added ones.

Parameters:

  • string $method The request method (e.g. 'get', 'post', 'options' ...). It can be in upper case or lower case.
Returns: booleanIf the given request method is remove, the method will return true. Other than that, the method will return true.
public function send(string$conentType, mixed$data, int$code)Sends Back a data using specific content type and specific response code.

Parameters:

  • string $conentType Response content type (such as 'application/json')
  • mixed $data Any data to send back. Mostly, it will be a string.
  • int $code HTTP response code that will be used to send the data. Default is HTTP code 200 - Ok.
public function sendResponse(string$message, string$type, int$code, mixed$otherInfo)
Sends a JSON response to the client. The basic format of the message will be as follows:

{
  "message":"Action is not set.",
  "type":"error"
  "http-code":404
  "more-info":EXTRA_INFO
}

Where EXTRA_INFO can be a simple string or any JSON data.

Parameters:

  • string $message The message to send back.
  • string $type A string that tells the client what is the type of the message. The developer can specify his own message types such as 'debug', 'info' or any string. If it is empty string, it will be not included in response payload.
  • int $code Response code (such as 404 or 200). Default is 200.
  • mixed $otherInfo Any other data to send back it can be a simple string, an object... . If null is given, the parameter 'more-info' will be not included in response. Default is empty string. Default is null.
public function setIsAuthRequred(boolean$bool)Sets the value of the property 'requreAuth'. The property is used to tell if the authorization step will be skipped or not when the service is called.

Parameters:

  • boolean $bool True to make authorization step required. False to skip the authorization step.
public function setManager(WebServicesManager|null$manager)Associate the web service with a manager. The developer does not have to use this method. It is used when a service is added to a manager.

Parameters:

  • WebServicesManager|null $manager The manager at which the service will be associated with. If null is given, the association will be removed if the service was associated with a manager.
public function toJSON()
Returns a Json object that represents the service. The generated JSON string from the returned Json object will have the following format:

{
  "name":"",
  "since":"",
  "description":"",
  "request-methods":[],
  "parameters":[],
  "responses":[]
}

Returns: Jsonan object of type Json.
mdi-menuAll Classesmdi-chevron-leftAnchorBrCodeSnippetHTMLDocHTMLListHTMLNodeHTMLTableHeadNodeInputJsCodeLabelListItemOrderedListParagraphRadioGroupTableCellTableRowUnorderedListInvalidNodeNameExceptionTemplateNotFoundExceptionCaseConverterJsonJsonConverterJsonIJsonTypesPropertyAPIFilterAbstractWebServiceManagerInfoServiceParamTypesRequestRequestParameterResponseUriWebServicesManagerAccessAutoLoaderConfigConfigControllerDBEAbstractWebServiceExtendedWebServicesManagerFileLoggerPrivilegePrivilegesGroupThemeThemeLoaderUploadFileUploaderUserUtilWebFioriAppLanguageErrorBoxHTTPCodeViewMessageBoxServerErrViewStarterPageWebPageDatabaseSessionStorageDefaultSessionStorageMSSQLSessionDataTableMSSQLSessionsTableMySQLSessionDataTableMySQLSessionsTableSessionSessionOperationsSessionStorageSessionsManagerRouterRouterUriAbstractMiddlewareMiddlewareManagerEmailMessageSMTPAccountSMTPServerClassLoaderExceptionFileExceptionInitializationExceptionInvalidCRONExprExceptionMissingLangExceptionNoSuchThemeExceptionRoutingExceptionSMTPExceptionSessionExceptionUIExceptionAbstractJobCronCronEmailCronJobJobArgumentCronLoginViewCronTasksViewCronViewCronLoginServiceCronLogoutServiceCronServicesManagerForceCronExecutionServiceGetJobsServiceCLICLICommandInputStreamOutputStreamStdInStdOutClassWriterLangClassWriterQueryClassWriterServiceHolderThemeClassWriterWebServiceWriterCreateCLIClassHelperCreateCronJobCreateMiddlewareCreateTableCreateTableObjCreateThemeHelperCreateWebServiceAddCommandCreateCommandCronCommandHelpCommandListCronCommandListRoutesCommandListThemesCommandRunSQLQueryCommandSettingsCommandTestRouteCommandUpdateSettingsCommandUpdateTableCommandVersionCommandAbstractQueryColumnColumnFactoryConditionConnectionConnectionInfoDatabaseDatabaseExceptionDateTimeValidatorEntityMapperExpressionForeignKeyJoinTableResultSetSelectExpressionTableWhereExpressionMySQLColumnMySQLConnectionMySQLQueryMySQLTableMSSQLColumnMSSQLConnectionMSSQLQueryMSSQLTableAbstractCollectionComparableLinkedListNodeQueueStack
Powered By: WebFiori Framework, Vue and VuetifyAll Rights Reserved © 2018 - 2024