Customizing and configuring REST resources using the BOD mapping framework
REST services are built on top of OAGIS services, and use an access profile and XPath to get data from an OAGIS noun. The access profiles used by REST services are defined in a configuration file by default. You can extend the configuration file to overwrite the data mapping.
The default configuration file is contained in the following location:- Rest.war/WEB-INF/config/com.ibm.commerce.rest/wc-rest-resourceconfig.xml
- Rest.war/WEB-INF/config/com.ibm.commerce.rest-ext/wc-rest-resourceconfig.xml
Customizing REST resources
When customizing the configuration file, you must consider the following factors:
- Decide which resource name you want to customize. For example,
productview
. - Decide which
GetUri
you want to customize. For example, the firstGetUri
in the following snippet that gets products by part number:<Resource name="productview"> <GetUri uri="store/{storeId}/productview/{partNumber}" description="Get product by part number" accessProfile="IBM_Store_CatalogEntrySearch" searchProfile="IBM_findCatalogEntryAll"/> <GetUri uri="store/{storeId}/productview/byId/{productId}" description="Get product by unique ID" accessProfile="IBM_Store_CatalogEntrySearch" searchProfile="IBM_findCatalogEntryAll"/> <GetUri uri="store/{storeId}/productview/byCategory/{categoryId}" description="Get products by category unique ID" accessProfile="IBM_Store_Details" searchProfile="IBM_findCatalogEntryByNameAndShortDescription"/> <GetUri uri="store/{storeId}/productview/bySearchTerm/{searchTerm}" description="Search products by search term and meta data" accessProfile="IBM_Store_CatalogEntrySearch" searchProfile="IBM_findCatalogEntryByNameAndShortDescription"/> </Resource>
- Then, create your own wc-rest-resourceconfig.xml file under the following directory:
- Search-Rest/WEB-INF/config/com.ibm.commerce.rest-ext
Copy theGetUri
elements that you want to use to your extension file, and change theaccessProfile
orsearchProfile
to meet your needs. For example:<ResourceConfig> <Resource name="productview"> <GetUri uri="store/{storeId}/productview/{partNumber}" description="Get product by part number" accessProfile="MyCustomProfile"/> </Resource> </ResourceConfig>
If you extend the search profile, you must also specify the search profile. For example:<ResourceConfig> <Resource name="productview"> <GetUri uri="store/{storeId}/productview/{partNumber}" description="Get product by part number" accessProfile="MyCompany_Store_Warranty" searchProfile="IBM_findProductByIds_Details,IBM_findProductByIdsWithAttributesAndAttachments,IBM_findProductByIds_Summary,IBM_findProductByIds_Summary_WithNoEntitlementCheck,IBM_Admin_findProductByIds,X_MySearchProfile"/> </Resource> </ResourceConfig>
REST services pass the search profile to the underlying OAGIS service. If no search profile is specified in your extension wc-rest-resourceconfig.xml, the default search profile defined in wc-rest-resourceconfig.xml is used.
- After completing your customization scenarios, you must restart your HCL Commerce server.
Example: Defining the URI for retrieving data
You can use the following sample snippets to retrieve
data:
<Resource name="productview">
<GetUri uri="store/{storeId}/productview/{partNumber}" description="Get product by part number"
accessProfile="IBM_Store_CatalogEntrySearch" searchProfile="IBM_findCatalogEntryAll"/>
<GetUri uri="store/{storeId}/productview/byId/{productId}" description="Get product by unique ID"
accessProfile="IBM_Store_CatalogEntrySearch" searchProfile="IBM_findCatalogEntryAll"/>
<GetUri uri="store/{storeId}/productview/byCategory/{categoryId}" description="Get products by category unique ID"
accessProfile="IBM_Store_Details" searchProfile="IBM_findCatalogEntryByNameAndShortDescription"/>
<GetUri uri="store/{storeId}/productview/bySearchTerm/{searchTerm}" description="Search products by search term and meta data"
accessProfile="IBM_Store_CatalogEntrySearch" searchProfile="IBM_findCatalogEntryByNameAndShortDescription"/>
</Resource>