Creating Custom Rest API controller

Hi,

How do I create a custom REST API controller in Cuba Studio?
Where do I place the controller class?
This controller has no relation to any Generic UI Screen just a simple Rest Controller.

How does this controller get generated by the Front-end Generator in the Typescript SDK?
I can’t seem to find the steps in any of the guides.

Thank you.

Kind Regards,
John

Hi,

I hope this example will answer your questions. It exposes a service using custom REST API controller and Generic REST features.

Classes of interest:
com.company.throttler.portal.controllers.TestRestController
com.company.throttler.service.HelloServiceBean

We’d recommend using portal module for the custom REST, but you can place it to the web module as well using standard Spring’s annotations.

Also, have a look at the documentation on securing custom REST controllers.

Hi,

I was uunder the impresetion that for Portal is using MVC dan requires a view.
The controller that I mean does not require a view.

Is portal still suitable even though I don’t have a view?

What kind of security do I need to take into consideration if there are no views?

Thanks.

Kind Regards,
John

1 Like

Please have a look at the example that I provided. You don’t need a view to publish a custom REST API in the portal module.

If you don’t specify any additional security, all endpoints in the portal module will be protected using BASIC authorization, so you can use your username/password specified in CUBA application.

Thanks for the info.
Let me study the example first.

Kind Regards,
John