Create custom API endpoint

We have a system we need to integrate into our cuba application. We can’t really change this system as of now and it doesn’t have support for Oath2, which the REST-API uses for authentication. What would be the easiest way to simply handle a custom incoming POST request? I thought about making a portal module and simply map a route that way, but is there maybe an easier way?

Hi,

you can create Spring MVC based custom controllers directly in the web application either with the oauth based security in place, or without.

Here’s an example I did back in the day, which defines a custom Spring MVC controller in the application:

In particular the controller: cuba-example-component-twilio/TwilioWebHookController.java at master · mariodavid/cuba-example-component-twilio · GitHub

In the README you can find more information on how to register it in the application.

Bye
Mario

2 Likes

Thanks Mario, exactly what I needed!

Hi Mario!

This should maybe me a new thread, but I will try here anyways.

I have created the Spring controller and I’m using a custom authentication method. My problem is that now I need to commit to the database, but I don’t have access to EntityManager and DataManager checks security constraints so that doesn’t work. I tried to create beans in the global module but it seems they don’t have access to Entitymanager either. I tried to refer to the documentation but I’m kinda stuck, maybe you can help?