ART#401 - ATG REST MVC Basics





A lot of us might've heard the term ATG REST or REST API but a lot of us don't get a chance to work on it OR don't exactly know what it is OR why do we exactly use it.
We will cover everything right from the basics as we always do.

What is REST?

You might've googled it a lot of times, and a lot of websites simply say REST stands for Representation State Transfer, along with some weird content which none of us understand. Let us understand what is REST and why is it used.

Let's take a basic scenario, wherein an order is submitted on a website, and all the details of the order (items, cost of each item, order total, time of placing order etc.) has to be sent to another system (for auditing purposes). The two systems are entirely different, one that hosts an eCommerce website with all the eCommerce functionality; and another system just takes order details and saves it for auditing purposes for calculation of monthly revenue, monthly profit, calculation of most sold items etc.
The architectures of these two systems are entirely different, and there may be a possibility that two different organizations handle them. The architecture of one system may not be known by another system.
In such a case, the order details have to be sent in a format which can be read by both the systems. For this purposes, XML or JSONs are used.
This is the example of order details in XML or JSON formats:
Sample JSON Format:
orderDetails: {
"orderId":"ord123456",
"orderTotal": 400,
"orderSubmitDate": "23-NOV-2017 13:33:44:00"
"items": [{
"itemId": "itm100002",
"itemName": "blah blah",
"listPrice": 200,
"discount": 0
},
{
"itemId": "itm100003",
"itemName": "blah blah",
"listPrice": 200,
"discount": 0
}
]
}
Sample XML Format
<?xml version="1.0"?>
<orderDetail>
<orderId>ord123456</orderId>
<orderTotal>400</orderTotal>
<orderSubmitDate>23-NOV-2017 13:33:44:00</orderSubmitDate>
<items>
<item>
<itemId>itm100002</itemId>
<itemName>blah blah</itemName>
<listPrice>200</listPrice>
<discount>0</discount>
</item>
<item>
<itemId>itm100003</itemId>
<itemName>blah blah</itemName>
<listPrice>200</listPrice>
<discount>0</discount>
</item>
</items>
</orderDetail>

These kind of formats (XML or JSON) can be easily parsed by any system with minimal effort. Therefore you have "represented" your data in a uniform format. This format is called REST format. The APIs which consume data in REST or transform their own data in REST format are called REST APIs.
Let's have a look at what ATG REST offers.

What is ATG REST?

ATG offers a way of exposing its API using its own REST Framworks. For example, if you want to integrate ATG with a mobile app which consumes only REST data, this is the way to go. The ATG's REST API allows you to call droplets, formhandlers, component methods and return a response in the form of XML or REST (you can configure that very easily).
Currently, ATG has two types of REST services viz.:
1. Legacy REST Web Services 
2. REST MVC Web Services
Since Legacy REST has its own limitations, it is currently obsolete. Therefore, we will talk about REST MVC Web Services of ATG.




How to enable REST Services in ATG?

While adding modules in CIM configuration OR in your ant script for building the application, add the module "REST" an build the ear.
You will have REST services enabled in your ATG application.

Now, lets see how we can run our first ATG REST Service!


No comments:

Post a Comment

Subscribe

Get All The Latest Updates Delivered Straight Into Your Inbox For Free!

Flickr