-
Notifications
You must be signed in to change notification settings - Fork 0
RestService
The RestService class extends the BaseService class, providing specialized functionality for interacting with RESTful web services in Salesforce Commerce Cloud (SFCC). It simplifies the process of creating and managing HTTP requests, handling various content types, and parsing complex responses.
Inherits from: BaseService
Description: Executes a REST service call based on the provided parameters. It utilizes the createRequest and parseResponse methods to manage the request and handle the response.
-
Parameters:
-
params(RestParams): The parameters for creating and executing the REST service request.
-
-
Returns:
-
dw.svc.Result: The result of the service call, either success or error.
-
Description: Creates an HTTP request for the REST service.
-
Parameters:
-
svc(dw.svc.HTTPService): The HTTP service instance. -
params(RestParams): The parameters for creating the request.
-
-
Returns:
-
string | dw.net.HTTPRequestPart[] | undefined: The request body, if applicable.
-
Description: Parses the HTTP response for the REST service.
-
Parameters:
-
svc(dw.svc.HTTPService): The HTTP service instance. -
response(dw.net.HTTPClient): The HTTP response.
-
-
Returns:
-
string | Object: The parsed response content.
-
Description: Sets a custom Authorization header and disables Basic Authentication.
-
Parameters:
-
svc(dw.svc.HTTPService): The HTTP service instance. -
auth(Authentication): The authentication configuration.
-
Description: Transforms the data object into a string or uses dw.net.HTTPRequestPart[] depending on the specified data type.
-
Parameters:
-
svc(dw.svc.HTTPService): The HTTP service instance. -
dataType(RestParams['dataType']): The type of data being sent (e.g., JSON, XML, form data). -
data(any): The data to be sent in the request.
-
-
Returns:
-
string | dw.net.HTTPRequestPart[]: The formatted request body.
-
Description: Transforms a data object into a URI-encoded string for form submissions.
-
Parameters:
-
svc(dw.svc.HTTPService): The HTTP service instance. -
data(Object.<string,string>): The data to be sent in the request.
-
-
Returns:
-
string: The formatted form body.
-
Description: Transforms a data object into a JSON string.
-
Parameters:
-
svc(dw.svc.HTTPService): The HTTP service instance. -
data(Object.<string,string>): The data to be sent in the request.
-
-
Returns:
-
string: The formatted JSON body.
-
Description: Transforms a data object into an XML string.
-
Parameters:
-
svc(dw.svc.HTTPService): The HTTP service instance. -
data(Object.<string,string>): The data to be sent in the request.
-
-
Returns:
-
string: The formatted XML body.
-
Description: Prepares a multipart/form-data request body.
-
Parameters:
-
svc(dw.svc.HTTPService): The HTTP service instance. -
data(dw.net.HTTPRequestPart[]): The multipart data to be sent.
-
-
Returns:
-
dw.net.HTTPRequestPart[]: The multipart request parts.
-
Description: Prepares a multipart/mixed request body.
-
Parameters:
-
svc(dw.svc.HTTPService): The HTTP service instance. -
data(Object): The multipart data, including boundary and parts.
-
-
Returns:
-
string: The formatted multipart body.
-
Description: Parses the HTTP response body for the REST service based on the content type.
-
Parameters:
-
contentTypeObject(ContentHeader): The content type object parsed from the response. -
response(dw.net.HTTPClient): The HTTP response.
-
-
Returns:
-
string | Object: The parsed response content.
-
Description: Parses a multipart/form-data response body.
-
Parameters:
-
boundary(string): The multipart boundary. -
responseBytes(dw.util.Bytes): The raw response body.
-
-
Returns:
-
MultipartChunk[]: The parsed multipart chunks.
-
Description: Parses a multipart/mixed response body.
-
Parameters:
-
boundary(string): The multipart boundary. -
responseBytes(dw.util.Bytes): The raw response body.
-
-
Returns:
-
MultipartChunk[]: The parsed multipart chunks.
-
Represents an authentication configuration.
-
Type:
Object-
type(string): The type of authentication (e.g.,Bearer,Basic). -
credentials(string): The authentication credentials.
-
Represents parameters for the REST service.
-
Type:
Object-
method("GET" | "PUT" | "POST" | "DELETE"): The HTTP method. -
auth(Authentication): The authentication configuration. -
pathPatterns(Object.<string,string>): The path pattern replacements. -
queryParams(Object.<string,string>): The query parameters. -
headers(Object.<string,string>): The request headers. -
dataType('form' | 'json' | 'xml' | 'multipart' | 'mixed'): The type of data being sent. -
data(any): The data to be sent in the request. -
outFile(dw.io.File): The output file for the response body. -
keyRef(dw.crypto.KeyRef): The key reference for mutual TLS. -
encoding(string): The encoding of the request body. -
ttl(number): The time-to-live for caching GET requests. -
getAuthentication(function): Callback for customizing the authentication object. -
onCreateRequest(function): Callback for customizing the request.
-