Is it possible to create custom API without using connectors in Oracle MCS?

248 views Asked by At

I want to create custom API without using connectors.I want to provide my data and then want to access them in mobile through custom API.

"getLIST": {
  "PendingList": [
    {
      "TRANSACTION_ID": "1612342887",
      "TRANSACTION_STEP_ID": "2344",
      "SIT_NAME": "Certificate Request",
      "PERSON_ID": "3435",
      "FROM_USER": "Rahul",
      "STATUS": "Pending",
      "FUTURE1": null,
      "FUTURE2": null,
      "FUTURE3": null,
      "FUTURE4": null,
      "FUTURE5": null
    },{
      "TRANSACTION_ID": "161234887",
      "TRANSACTION_STEP_ID": "143234840",
      "SIT_NAME": "Certificate Request",
      "PERSON_ID": "3436",
      "FROM_USER": "Sashanka",
      "STATUS": "Pending",
      "FUTURE1": null,
      "FUTURE2": null,
      "FUTURE3": null,
      "FUTURE4": null,
      "FUTURE5": null
    },
]
}

If I provide above JSON payload in response,and through this custom api "/mobile/customtest/getLIST/PendingList?PERSON_ID=3435" ,can I get the details

Is it possible??

3

There are 3 answers

1
Chris Muir On

What the OP wants to achieve is still unclear, but in purely answering the question around searching a hardcoded JSON array and returning a result, the following code shows such an example based on an "Employees" array:

module.exports = function(service) {

    var employees = [
          {
            "id": "103",
            "username": "rbarkhouse",
            "firstName": "Rick",
            "lastName": "Barkhouse"
          },
          {
            "id": "107",
            "username": "kbrown",
            "firstName": "Karen",
            "lastName": "Brown"
          },
          {
            "id": "108",
            "username": "ldavies",
            "firstName": "Larry",
            "lastName": "Davies"
          }
        ];

    service.get('/mobile/custom/hrapi/employee', function(req,res) {
        res.send(200, employees);
    });

    service.get('/mobile/custom/hrapi/employee/:id', function(req,res) {
        var id = req.params.id;

        var employee =
            employees.filter(function(el) { return el.id == id; });

        if (employee == null) {
            res.send(404);
        } else {
            res.send(200, employee[0]);
        }
    });
  };

Note the use of the employees array "filter" function, where we pass in an anonymous function that is capable of searching through the employees elements returning that matches ":id" passed in as a URL parameter.

1
Joe On

Absolutely! Follow the docs here and video here. While, yes we typically use a custom API to act as a wrapper around another service call via a connector, you don't have to do that, If you just want to return a fixed/static payload you can add that as the response to the GET call.

BUT - if you expect to search the array, etc then that is more work and should be done in a service - hence the need for a connector.

Instructions here: Add the basics (name of the API, the message media type, and a brief description).

Define an endpoint by setting a resource and at least one method for it.

Set access security.

Test your endpoint after you've defined at least one resource. To fully complete your API, use the API Designer to help you add the essential components for a robust API:

Provide the API metadata (that is, the basic attributes of the API, which are the API display name, API name, and short description) or, if you already have a RAML document that contains the configuration of your API, then you can upload it to the API Designer. All the information (metadata, resources, methods, and the schema for the message body) is extracted from the RAML document and loaded into the API Designer, letting you quickly proceed to testing your endpoints or editing your API configuration. To provide a valid RAML file, see RAML.

Add one or more root and nested resources.

Add methods to act on the resources.

Create a schema to describe the body of data.

Test your endpoints during design time with sample data and make any changes as needed.

Allow anonymous access to your API or specify which roles can access it.

Add documentation for your custom API

3
Arj 1411 On

If you don't want to use MCS Connectors , Use platform Apis that MCS provides . You can create tables in MCS . Then use the Custom Apis to fetch data from tables .