ServiceRouterProtocol
@objc public protocol ServiceRouterProtocol
Public protocol implemented by the Service Router for service registration and processing requests.
See also
ServiceRouter
-
Registers the provided service class.
Declaration
Swift
@discardableResult func registerService(_ service: ServiceProtocol.Type) -> BoolParameters
serviceclass type meeting the ServiceProtocol type.
Return Value
true if registration was successful.
-
Unregisters the provided service class, if the service was previously registered.
If the service was not registered this method has no effect.
Declaration
Swift
func unregisterService(_ service: ServiceProtocol.Type)Parameters
serviceclass type meeting the ServiceProtocol type to unregister
-
Processes the provided request, routing the request to the appropriate service.
All processRequest methods should be considered asynchronous. Return closures may not be called on the same dispatch queue as the original request.
The request URL will be similar to:
http://pmapi/serviceid/extrapathDeclaration
Swift
func processRequest(_ request: URLRequest, responseBlock : @escaping responseReturnBlock, dataBlock : @escaping dataReturnBlock, completionBlock : @escaping requestCompleteBlock)Parameters
requestThe URLRequest to process
responseBlockFirst of three return closures. The service will call this closure to return response object back to the calling code.
dataBlockSecond of the three return closures. The service will call this closure to return data back to the calling code. This closure may not be called if the service does not return any data.
completionBlockThird and final of the three return closures. The service will call this closure when the service request has completed.
-
Constructs a basic GET request for given service identifier and processes the provided request, routing the request to the appropriate service.
All processRequest methods should be considered asynchronous. Return closures may not be called on the same dispatch queue as the original request.
The request URL will be similar to:
http://pmapi/serviceidDeclaration
Swift
func processRequest(serviceId: String, responseBlock : @escaping responseReturnBlock, dataBlock : @escaping dataReturnBlock, completionBlock : @escaping requestCompleteBlock)Parameters
serviceIdService Identifier, specifying the service that should process the request.
responseBlockFirst of three return closures. The service will call this closure to return response object back to the calling code.
dataBlockSecond of the three return closures. The service will call this closure to return data back to the calling code. This closure may not be called if the service does not return any data.
completionBlockThird and final of the three return closures. The service will call this closure when the service request has completed.
-
Constructs a GET request for given service identifier and processes the provided request, routing the request to the appropriate service.
All processRequest methods should be considered asynchronous. Return closures may not be called on the same dispatch queue as the original request.
The request URL will be similar to:
http://pmapi/serviceid/extrapathexamples, given a servideId of
serviceid
, and extraPath of:foo–> resulting url:http://pmapi/serviceid/foofoo/bar?some=query&another=value–> resulting url:http://pmapi/serviceid/foo/bar?some=query&another=value
Declaration
Swift
func processRequest(_ serviceId: String, extraPath: String?, responseBlock : @escaping responseReturnBlock, dataBlock : @escaping dataReturnBlock, completionBlock : @escaping requestCompleteBlock)Parameters
serviceIdService Identifier, specifying the service that should process the request.
extraPathOptional string to include in the request URL after the service identifier. This string may include any valid URL components, including multiple path depths, and query strings
responseBlockFirst of three return closures. The service will call this closure to return response object back to the calling code.
dataBlockSecond of the three return closures. The service will call this closure to return data back to the calling code. This closure may not be called if the service does not return any data.
completionBlockThird and final of the three return closures. The service will call this closure when the service request has completed.
-
Constructs a request for given service identifier and processes the provided request, routing the request to the appropriate service.
All processRequest methods should be considered asynchronous. Return closures may not be called on the same dispatch queue as the original request.
The request URL will be similar to:
http://pmapi/serviceid/extrapathexamples, given a servideId of
serviceid
, and extraPath of:foo–> resulting url:http://pmapi/serviceid/foofoo/bar?some=query&another=value–> resulting url:http://pmapi/serviceid/foo/bar?some=query&another=value
Declaration
Swift
func processRequest(_ serviceId: String, extraPath: String?, method: String, data: Data?, responseBlock : @escaping responseReturnBlock, dataBlock : @escaping dataReturnBlock, completionBlock : @escaping requestCompleteBlock)Parameters
serviceIdService Identifier, specifying the service that should process the request.
extraPathOptional string to include in the request URL after the service identifier. This string may include any valid URL components, including multiple path depths, and query strings
methodHTTP method string to use for the request, i.e.
GET
,POST,
PUT,
DELETE,
OPTION", etc.dataBody data to include in the request.
responseBlockFirst of three return closures. The service will call this closure to return response object back to the calling code.
dataBlockSecond of the three return closures. The service will call this closure to return data back to the calling code. This closure may not be called if the service does not return any data.
completionBlockThird and final of the three return closures. The service will call this closure when the service request has completed.
View on GitHub
ServiceRouterProtocol Protocol Reference