0

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??

Janaki Narayanan
  • 523
  • 6
  • 24
  • Could you clarify your requirement please? When you say you don't want to use a connector, what does that have to do with the payload you've described? Do you simply want to hardcode the response in your Custom API to include the above payload, but, you want to search through the JSON array where person_id=3435? – Chris Muir Jan 10 '17 at 00:33
  • yes...I want to hardcode the response and search through the JSON array . – Janaki Narayanan Jan 10 '17 at 05:40
  • I don't think that is possible. See Anand's suggestion to load your data into an MCS table and then search that programmatically with your custom API – Joe Jan 10 '17 at 14:44
  • Just wante to know , Why do you opt Custom Apis without connectors ? – Arj 1411 Jan 17 '17 at 09:27

3 Answers3

0

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

Joe
  • 3,337
  • 1
  • 14
  • 11
0

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 .

Arj 1411
  • 1,395
  • 3
  • 14
  • 36
  • OP will still need to load the tables with data. He will not be able to search "static" JSON in a custom API. Docs for the Platform Database tables is here: http://docs.oracle.com/en/cloud/paas/mobile-cloud/mcsua/database-apis.html#GUID-F7AA3E02-7679-4E1E-8792-C6C80042F362 – Joe Jan 10 '17 at 14:43
  • Didn't get what you said – Arj 1411 Jan 11 '17 at 06:26
  • he has to store his data in the database API and then can search that and return the results - he does not have to use a connector. The DB API is accessed and manipulated via REST calls. SO it will take some custom cod eon his part to do what he wants. – Joe Jan 11 '17 at 16:33
0

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.

Chris Muir
  • 445
  • 2
  • 8