Answer the question
In order to leave comments, you need to log in
What is the minimum set of JAVA tools for working with a REST API service?
It is necessary to accept and process POST, GET requests in JSON format.
Answer the question
In order to leave comments, you need to log in
Is it possible to do without controllers?
@RestController
@RequestMapping("/books")
public class BooksService {
@Autowired
private BooksRepository booksRepository;
/**
* Список книг
*/
@RequestMapping
public ResponseEntity list() {
return ResponseEntity.ok(booksRepository.findAll());
}
/**
* Добавление новой книги
*/
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity create(@RequestBody Book book) {
return ResponseEntity.ok(booksRepository.save(book));
}
/**
* Получение существующей книги
*/
@RequestMapping("/{id}")
public ResponseEntity get(@PathVariable String id) {
if (bookRepository.exists(id)) {
return ResponseEntity.ok(booksRepository.save(book));
}
return ResponseEntity.notFound().build();
}
}
Is Spring required in a task?
There is a very simple and lightweight Play framework. Preferred Scala language.
nordicapis.com/building-a-rest-api-in-java-scala-u...
import play.api._
import play.api.mvc._
object Application extends Controller {
def getName = Action {
Ok("Jim")
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question