Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

WebAPI controller

The WebAPI controllers, built by Optimizely for each of the Commerce (SaaS) modules, serve as the endpoint for the RESTful based services.

The WebAPI controller contains the RoutePrefix which identifies its RESTful path.

Commerce (SaaS) modules that expose a RESTful API layer must derive from BaseApiController. Deriving from BaseApiController allows WebAPI controllers to understand and interact with context, cookies, and standardize a properties collection on all JSON objects. This properties collection stores any extensions to the JSON object with a key/value pair.

For example, use the properties collection to store custom properties from the Management Console.

Once the WebAPI controller derives from BaseApiController it contains methods that map to the service methods in typescript services and thus, the HTTP verbs. Each WebAPI controller method is decorated with a Route attribute which, in combination with RoutePrefix, provides a full path to the RESTful service.

The Parameter Object and Result Object patterns are used to clump common objects together for consistent calls to and from service methods. This means that parameters are clumped using the Parameter Object pattern and objects returned from a function use the Result Object pattern.

The Data Mapper design pattern is used to map the service result object to the WebAPI return object. The data mapper will also map the WebAPI parameters to the service parameter objects.

var accountModel = this.ObjectToObjectMapper.Map<GetAccountResult, AccountModel>(serviceResult);