Help with rest API - custom url mapping

I’m trying the rest api plugin for the first time… Im having problems getting started on a simple task of creating a custom url mapping. i dont have a portal. it should be on a web screen controller?

I dont know where to put this file? Do I have to create it on the beans.
I dont want queries or anything else just create a simple mapping and return a string
I added cuba.rest.anonymousEnabled = true
to test on the web-app.properties file.

package com.company.test.portal.myapi;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.company.test.services.SomeService;

@RestController
@RequestMapping("/myapi")
public class MyController {

@Inject
protected SomeService someService;

@GetMapping("/dosmth")
public String doSmth() {
    return "HELLO"
}

}

I’d like to see the response on
localhost:8080/app/myapi/dosmth

thanks for the help

Hi,
Creating custom oauth-protected REST API controllers is described here:
https://doc.cuba-platform.com/restapi-7.2/#rest_api_v2_custom_controllers

Hello. thank you for your response. Thats where I copied the example I i posted. wanted anonymous access… no OAuth. Also, I have no idea where that class has to go.

Hi,
If you don’t need OAuth authentication, then you can just create a Spring MVC controller in the web module. However you would need to setup some security settings, because CUBA will not allow you to read any data with DataManager without specifying a user session in your code.

Since similar questions are being asked from time to time, I’ve created a sample project. Description is in its README.md file.