REST API End Point

Pretty new to the API Services on the Business Logic side on Backendless so forgive any wrong terminology!

Following Marks (excellent) video made good headway beginning an api.

I can successfully run a GET request like this…
https://api.backendless.com/xxx/xxx/services/APIService/myCustomers?id=3

and my corresponding simple code in the business logic code area is this.
/**

  • @route GET /myCustomers
  • @param {int} id
    */
    helloCustomer( id ){
    return "hello customer id: " + id;
    }

but what I can’t achieve is getting the ID without using a parameter in the URL. I need this as I have to produce an endpoint more like this (as requested by another 3rd party app)
https://api.backendless.com/xxx/xxx/services/APIService/myCustomers/3

Is this possible and if so could you show me the code?

Many thanks.

Mike

Hi Mike
Yes, it’s possible, you can override request method and request route as well
here is a doc for that REST Routes - Developing Backendless Server Code with node.js

and a simple example:

'use strict';

class SampleService {
  /**
   * @route GET /my-custom-route/items/{itemId}
   * @returns {Object}
   */
  getItem() {
    const { itemId } = this.request.pathParams
    
    return { 
      itemId
    }
  }
}

Backendless.ServerCode.addService(SampleService);

1 Like

Excellent, thanks Vladimir.

That works perfectly, just what I wanted.

good, glad to hear it

hey vladimir, sorry to bother but i need some help.
I copy/pasted your code,and my result is

{
“itemId”: “services”
}

i don’t get why, can youn please help?
i need to achieve same results

Hi Atellani

Confirm, it doesn’t work correctly now. I’ve created an internal ticket to solve the issue.
Ticket number for reference BKNDLSS-18563

Regards, Vlad

thanks a lot Vladimir, keep us posted then!

@Atellani_Brid @mike-turner

Hello guys, we have fixed the issue. Please check if everything fine for you.

Sorry we have to revert the fix because of reggression. We will notify you when we fix it

And we fix it again. Sorry for this regressions.

yes it works now!
thanks a lot to you all, good job!