Splitting API and web app

Hi, in the book, after creating the web app, it is suggested that we could split up the web app from the API for a large project, and then having the web app talking to the API, but I don’t fully understand how this could be achieved…
I imagine that the web app should handle the routes, then send a request to the API to get the objects it needs, and finally return a Leaf view for example ; am I correct ?

I haven’t read the book, but that’s the way it should be. The web App should be another client of the REST API as the mobile Apps are, and be decoupled from the API.

@0xtim Can you please help with this when you get a chance? Thank you - much appreciated! :]

@ericlm as @david6p2 says yep that’s right. The Vapor web front-end will send requests to the API (to multiple APIs or endpoints if necessary) handle authentication with the API (such as converting cookies to API tokens) and providing all the necessary data to the Leaf template

All right ! Thank you very much @0xtim and @david6p2 !

By doing this way, will there be any delay in response time ?

I am asking this because internally server makes another HTTP Request to server.

@0xtim Do you have any feedback about this? Thank you - much appreciated! :]

@vigneshkumar yes there will be a small delay in response time, but no different to an iOS app. Given modern server applications and made up of tens or hundreds of microservices, as long as you ensure they have a good connection (i.e. deploy them in the same datacenter etc) it shouldn’t be noticeable.

1 Like