Thursday, March 17, 2016

Accessing Oracle Mobile Cloud Service (MCS) REST from Postman

Do you want to test in your environment REST service running on Oracle MCS cloud? I have implemented public REST service hosted on Oracle MCS, you can call it from Postman application (Google Chrome extension).

Implemented use case - SOAP Connector in MCS is reading Stock Quote information for the company supplied in the request. Information is transformed by MCS Custom API (with Node.js) into REST structure and returned to the client through MCS Mobile backend.

Here is the REST GET url to invoke in Postman: https://mobileportalsetrial1304dev-mcsdem0001.mobileenv.us2.oraclecloud.com:443/mobile/custom/STOCKQUOTE_API_REDSAMURAI_BLOG_1/stockquote/ORCL. Try to run it, you can replace ORCL with another company ID. To execute this REST request in Postman, you need to provide configuration file (this allows to call MCS). Configuration file can be downloaded from here - Postman_MCS_1.json. This file contains all required info to make REST request from Postman:


To add configuration file to Postman, go to Configuration and upload it through Import data option:


Make sure MCS profile is selected:


When you copy paste REST URL, go to Headers section and select MCS from Presets - this will add two required headers:


You should see company stock information returned back from REST call:


Let's switch to MCS. There are three main concepts in MCS - Mobile Backend, custom API, Connector. Mobile Backend is a service interface, it allows to configure mobile access functionality and contains a list of Web Services (API's) exposed to the clients. It allows to track service usage and view statistics in the dashboard:


My example contains single Web Service (custom API). This service is responsible to handle REST GET method and return company stock quote data:


Custom API defines REST resource /stockquote/{company}, this is what we are executing in Postman URL:


Resource /stockquote/{company} is configured with GET method:


GET method is configured to handle two type of responses - 200 (OK) and 404 (Not Found):


To provide API implementation (mapping between Connector and API response), we can download (see example - stockquote_api_redsamurai_blog_1.zip) Node.js file from MCS and edit it locally (edited file can be uploaded back in the archive):


We need to specify Connector name to be available in Node.js, this is how it will call Web Service defined in the Connector:


Node.js function is responsible to call Web Service from Connector, pass parameter and check the result (here you can do complex transformations between SOAP and REST):


I'm using SOAP connector, pointing to external Web Service to fetch Stock Quote information for the company:

No comments: