Add data to response on the fly

Hi,
I will really appreciate any help.

I would like to insert some data I get from 3rd party API to the get response of a list and a single item, what is the best way to do it?

Create custom API service from business logic or there is an easier way for it?

Let’s have an example, I have list of cities stored in Backandless and when I query this list I would like to include weather/temperature in the response for each city instead of making N requests on the client.

Thanks a lot,
best,
Nick.

Hi Nick,

There are two approaches to accomplish what you want:

  1. Using an event handler
  2. Using an API service

The first approach would be simpler (IMHO) since you’d be getting a collection of retrieved objects and can enrich it in your code/logic. With the second approach, you’d need to fetch objects and then enrich each of them.

Will you be using Codeless or code to implement this?

Regards,
Mark

I would use code I think. I was thinking to go with event handler, but I do not see a handler for get operation. Only for find or first which is only for one item, can you point me to a handler when you get all the items from the table, please? Thanks!

This is the handler you need:

Once the handler is created, you can edit the code right in the console. The arrow in the screenshot below points to the object that will have the collection objects you need to enrich:

Hope this helps.

Mark

Thanks, will try it, seems like a solution I was looking for! Have a great day!