Custom REST API endpoint

Hi,
I am using Springboot as my backend and inside the code there are some API endpoints such as

localhost:8080/latestDocuments301

where it will run the query

SELECT eg FROM table eg
            WHERE eg.libraryId = 301
            AND eg.publish = 2
            ORDER BY eg.publicationDate DESC
            LIMIT 5

I am planning to migrate to JMIX and use its REST API add on to expose the JMIX application. Is there any way that i can use the same endpoint i.e. /latestDocuments301 and map it to JMIX REST API endpoint or do I need to do a complete overhaul of all the endpoints in my Springboot. Thank you.

Best regards,
Amirul Mukminin

Hi Amirul,

Of course you can use custom endpoints together with Jmix generic REST.

For example, if you have the following REST controller:

@RestController
public class DocumentController {

    @GetMapping("/countLatestDocuments")
    public int countLatestDocuments() {
        return 42;
    }
}

you can secure it with the same token-based authentication mechanism as generic REST if you add its URL to the jmix.resource-server.authenticated-url-patterns property:

jmix.resource-server.authenticated-url-patterns = /rest/**,/countLatestDocuments

If you want to access this endpoint without authentication (i.e. as anonymous system user), add the URL to jmix.resource-server.anonymous-url-patterns property:

jmix.resource-server.anonymous-url-patterns=/countLatestDocuments

The anonymous user can be configured in the DatabaseUserRepository class of your project.

See Custom Endpoints :: Jmix Documentation for more information.

Regards,
Konstantin