Alex5207
Alex5207

Reputation: 484

Creating a front end for a nest-js API

I have a question regarding creating a front-end for a nest-js API:

  1. Will this front-end be an entirely different project with regards to folder structure?
  2. Will it just 'call' the services from my API?
  3. How are my controllers of the API used, if the front-end just uses the services directly?

Also, in what order does it make sense to create the front-end prior to auth? Or should it be the other way around.

Thanks

Upvotes: 7

Views: 16485

Answers (1)

Martin Adámek
Martin Adámek

Reputation: 18389

  1. You can create separate project for frontend app, or you could return HTML directly from nest. This depends on what you want.

    https://docs.nestjs.com/techniques/mvc

  2. If you go for server side rendering (the MVC link above), then your code will have direct access to your nest services. If you go for SPA approach (angular, react, vue, ...), then you will have to call your nest API via http, so you will have access only via your API endpoints.

  3. I guess this one is answer already - for SSR approach, you will have endpoints that return the HTML. You could combine both approaches, having group of controllers working as REST API, and another group for SSR, that will return JSON response.

About the auth - I guess you should implement the backend first, then you can implement frontend so you can test it.

Upvotes: 7

Related Questions