Off-load CMS Api calls to client

Hey, I’m curious if it’s possible to “offload” e.g. api calls to a cms but still use Vaadin Flow (no typescript). My first idea was to call the api in a method that’s called by the constructor of the view class, but that would mean that the traffic would be generated by my app right? Thanks in advance :slightly_smiling_face:

I don’t fully understand your requirement. Do you just want to call an API and then display the data?

Yeah, but I don’t want the Traffic to the API to be generated by my app, but rather by the user because the API is public anyway. This is also useful regarding the CDN of the api

This is not possible. How should this work?

Well in JavaScript you can make the browser to call a API, I hoped that it’ll be possible via Vaadin Flow too

Well you can write Javascript in flow that is executed on the client which calls the external API

With Flow you are programming on the server not on the client

Perfect reaction… not cool but technically possible…

Yeah, but I would need the Date on the Server. I hoped for a method that can execute a REST API call via the client and a callback that’s called when the client received the response
Like: Server sends blueprint of the request to client → Client executes that request and displays the data

Well the client can pass the data to the server as well

But there’s no in-built solution for that right?

The building blocks are there, you can create Javascript and in there you can do your stuff and later invoke a method on the server annotated with ClientCallable

Some examples

That seems to be what I need :slightly_smiling_face: Thank you I’ll take a look into that

As mentioned, it’s possible to do it. But in a way, you’re working against the the framework when doing so (instead of letting it help you). It’ll lead to more complexity in your code and more maintenance overhead down the road.

What is the reason you want to call the API from the client instead of from the server?

I would suggest calling the API from the server as a first solution and only optimizing if and when a need arises.

So the API uses a CDN, and I thought if the server is calling the API, the CDN doesn’t really makes sense then. Additionally I wanted to lower the traffic my app would generate to save some $.