Start a new topic
Answered

Custom Endpoint calling Custom Endpoint

Hello.


    How can I call a custom endpoint from within a custom endpoint?  I know that the HTML5 SDK has this method: Kinvey.CustomEndpoint.execute().  Do I have to use the REST API?  Example: modules.request.request(opts, function (error, resp, body) { });


Thank you.

 


Best Answer

Hello John,


Yes. You will have to use modules.request.request(). Check the following code for a better understanding:


var req = modules.request;
var endpointName = 'secondEndpoint';
var uriString = 'https://baas.kinvey.com/rpc/' + modules.backendContext.getAppKey() + '/custom/' + endpointName;
var opts = {
        uri: uriString,
        method: 'post',
        headers: {'Authorization': request.headers.authorization},
        json: true
    };

req.request(opts, function (err, resp, body) {
        if (err) {
            
        } else {
            
        }
});



Thanks,

Pranav

1 Comment

Answer

Hello John,


Yes. You will have to use modules.request.request(). Check the following code for a better understanding:


var req = modules.request;
var endpointName = 'secondEndpoint';
var uriString = 'https://baas.kinvey.com/rpc/' + modules.backendContext.getAppKey() + '/custom/' + endpointName;
var opts = {
        uri: uriString,
        method: 'post',
        headers: {'Authorization': request.headers.authorization},
        json: true
    };

req.request(opts, function (err, resp, body) {
        if (err) {
            
        } else {
            
        }
});



Thanks,

Pranav


1 person likes this
Login or Signup to post a comment