'How to call API endpoint in HTML
I'm trying to create a small web application that will generate random articles, It's not that important.
I have this one repository:
@Repository
public interface ArticleRepository extends MongoRepository<Article, String> {
@Aggregation(pipeline = {"{$sample:{size:1}}"})
AggregationResults<Article> random();
Btw. this will take one random record from database collection, again, not important.
This is my service:
@Override
public Article random() {
return articleRepository.random().getMappedResults().stream().findFirst().orElse(null);
}
And this is controller:
@GetMapping("/random")
public ResponseEntity<Article> random() {
return ResponseEntity.ok(articleService.random());
}
What I want, but don't know even how to start, is that I want for this example button, and when I press that button random article appears on the screen. So, plain HTML page, button inside it and on click activate that endpoint to generate random article.
I know I can use in controller return "page.html" but I want to have a special page for this, button inside and on click submit controller. If you need more code, or anything else, I'm here!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
