Browse Source

Implement REST API reference help page

Signed-off-by: Pekka Helenius <fincer89@hotmail.com>
v0.0.2-alpha
Pekka Helenius 4 years ago
parent
commit
02feca41d2
4 changed files with 127 additions and 0 deletions
  1. +16
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java
  2. +8
    -0
      bookstore/src/main/resources/messages.properties
  3. +83
    -0
      bookstore/src/main/resources/templates/apiref.html
  4. +20
    -0
      bookstore/src/main/resources/templates/booklist.html

+ 16
- 0
bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java View File

@ -47,6 +47,7 @@ public class BookController {
private CategoryRepository categoryRepository;
private static final String RestJSONPageView = "json";
private static final String RestAPIRefPageView = "apiref";
private static final String landingPageView = "index";
private static final String bookListPageView = "booklist";
@ -58,6 +59,7 @@ public class BookController {
private static final long serialVersionUID = 1L;
{
put("restpage", RestJSONPageView);
put("apirefpage", RestAPIRefPageView);
put("indexpage", landingPageView);
put("listpage", bookListPageView);
@ -236,6 +238,20 @@ public class BookController {
return "redirect:../" + bookListPageView;
}
//////////////////////////////
// API REFERENCE HELP PAGE
@RequestMapping(
value = RestAPIRefPageView,
method = { RequestMethod.GET }
)
public String webFormRestApiRef(
HttpServletRequest requestData,
HttpServletResponse responseData
) {
httpServerLogger.log(requestData, responseData);
return RestAPIRefPageView;
}
//////////////////////////////
// REDIRECTS


+ 8
- 0
bookstore/src/main/resources/messages.properties View File

@ -40,17 +40,23 @@ page.title.browser.list = Bookstore page
page.title.browser.add = Add book
page.title.browser.edit = Update book
page.title.browser.error = Error page
page.title.browser.apiref = API Reference help page
page.title.webform.list = Books
page.title.webform.add = Add new book
page.title.webform.edit = Update existing book
page.title.webform.error = Error
page.title.webform.apiref = API Reference help page
page.text.list.actions = Actions
page.text.list.delete = Delete
page.text.list.edit = Edit
page.text.list.json = Get
page.text.apiref.endpoints = REST API end points
page.text.apiref.examples = Direct search examples
page.text.apiref.add = Adding books (Unix-alike clients)
page.text.error = Error while processing your request
button.book.add = Add book
@ -59,4 +65,6 @@ button.book.edit = Update book
button.page.list.return = Return to book list page
button.page.list.json = Get list as JSON
button.page.apiref = How to: REST API link references
page.symbols.currency = \u20AC

+ 83
- 0
bookstore/src/main/resources/templates/apiref.html View File

@ -0,0 +1,83 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link type="text/css" rel="stylesheet" href="../static/css/bookstore.css" th:href="@{../css/bookstore.css}" />
<link type="text/css" rel="stylesheet" href="../static/css/bootstrap.min.css" th:href="@{../css/bootstrap.min.css}" />
<title th:text="${#messages.msgOrNull('page.title.browser.apiref')} ?: 'page.title.browser.apiref'">
page.title.browser.apiref
</title>
</head>
<body th:with="baseUrl=(@{__${#httpServletRequest.scheme}__} + '://' + @{__${#httpServletRequest.serverName}__} + ':' + @{__${#httpServletRequest.serverPort}__} + '/')">
<h1 th:text="${#messages.msgOrNull('page.title.webform.apiref')} ?: 'page.title.webform.apiref'">
page.title.webform.apiref
</h1>
<table class="table table-striped">
<tbody>
<tr>
<th><h3 th:text="${#messages.msgOrNull('page.text.apiref.endpoints')} ?: 'page.text.apiref.endpoints'">
page.text.apiref.endpoints
</h3></th>
</tr>
<tr>
<td>
<code th:text="${baseUrl} + 'api/booklist/'">placeholder</code>
</td>
</tr>
<tr>
<td>
<code th:text="${baseUrl} + 'api/categories/'">placeholder</code>
</td>
</tr>
</tbody>
</table>
<table class="table table-striped">
<tbody>
<tr>
<th><h3 th:text="${#messages.msgOrNull('page.text.apiref.examples')} ?: 'page.text.apiref.examples'">
page.text.apiref.examples
</h3></th>
</tr>
<tr>
<td>
<code th:text="${baseUrl} + 'api/booklist/search/title?name=Bloody+Chamber'">placeholder</code>
</td>
</tr>
<tr>
<td>
<code th:text="${baseUrl} + 'api/categories/search/category?name=Fantasy'">placeholder</code>
</td>
</tr>
</tbody>
</table>
<table class="table table-striped">
<tbody>
<tr>
<th><h3 th:text="${#messages.msgOrNull('page.text.apiref.add')} ?: 'page.text.apiref.add'">
page.text.apiref.add
</h3></th>
</tr>
<tr>
<td>
<code th:text="'curl --include --request POST --header &quot;Content-Type: application/json&quot; --data \'{&quot;title&quot;:&quot;The Witcher: Blood of Elves&quot;,&quot;author&quot;:&quot;Andrzej Sapkowski&quot;,&quot;year&quot;:1994,&quot;isbn&quot;:&quot;5474512-543&quot;,&quot;price&quot;:22.49}\' ' + ${baseUrl} + 'api/booklist'"></code>
</td>
</tr>
</tbody>
</table>
<form action="#" th:action="@{__${listpage}__}" method="get">
<button class="btn btn-success" type="submit"
th:text="${#messages.msgOrNull('button.page.list.return')} ?: 'button.page.list.return'">
button.page.list.return
</button>
</form>
</body>
</html>

+ 20
- 0
bookstore/src/main/resources/templates/booklist.html View File

@ -91,6 +91,26 @@
</td>
</tr>
<tr style="background-color: #FFF !important;">
<td>
<!-- We could use button + <form> here to have uniform styling for all buttons (CSS),
and maybe other benefits but since we don't submit any data here but use this element
only to access a href link, we keep this structure simple. Change if needed. -->
<a class="btn btn-info" th:href="@{__${apirefpage}__}"
th:text="${#messages.msgOrNull('button.page.apiref')} ?: 'button.page.apiref'">
button.page.apiref
</a>
</td>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</table>
</div>
</body>


Loading…
Cancel
Save