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) -> Bool
Parameters
service
class 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
service
class 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/extrapath
Declaration
Swift
func processRequest(_ request: URLRequest, responseBlock : @escaping responseReturnBlock, dataBlock : @escaping dataReturnBlock, completionBlock : @escaping requestCompleteBlock)
Parameters
request
The URLRequest to process
responseBlock
First of three return closures. The service will call this closure to return response object back to the calling code.
dataBlock
Second 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.
completionBlock
Third 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/serviceid
Declaration
Swift
func processRequest(serviceId: String, responseBlock : @escaping responseReturnBlock, dataBlock : @escaping dataReturnBlock, completionBlock : @escaping requestCompleteBlock)
Parameters
serviceId
Service Identifier, specifying the service that should process the request.
responseBlock
First of three return closures. The service will call this closure to return response object back to the calling code.
dataBlock
Second 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.
completionBlock
Third 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/extrapath
examples, given a servideId of
serviceid
, and extraPath of:foo
–> resulting url:http://pmapi/serviceid/foo
foo/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
serviceId
Service Identifier, specifying the service that should process the request.
extraPath
Optional 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
responseBlock
First of three return closures. The service will call this closure to return response object back to the calling code.
dataBlock
Second 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.
completionBlock
Third 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/extrapath
examples, given a servideId of
serviceid
, and extraPath of:foo
–> resulting url:http://pmapi/serviceid/foo
foo/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
serviceId
Service Identifier, specifying the service that should process the request.
extraPath
Optional 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
method
HTTP method string to use for the request, i.e.
GET
,POST,
PUT,
DELETE,
OPTION", etc.data
Body data to include in the request.
responseBlock
First of three return closures. The service will call this closure to return response object back to the calling code.
dataBlock
Second 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.
completionBlock
Third and final of the three return closures. The service will call this closure when the service request has completed.