To enable us to access our CDI services from AngularJS, we need to expose them over REST, though the use of REST is just one of the many choices that could have been made.
For retrieving books from our database, we need a REST service similar to the following:
@Path("/books") public class BookListResource { @Inject BookService bookService; @GET @Produces(MediaType.APPLICATION_JSON) public List<Book> getAvailableBooks() { List<Book> results = bookService.getAvailableBooks(); Collections.sort(results, new BookTitleSorter()); return results; } @GET @Path("/{categoryId}") @Produces(MediaType.APPLICATION_JSON) public List<Book> getAvailableBooksByCategory(@PathParam("categoryId") long categoryId) { Map<String, String> params = new HashMap<>(); params.put("available", "true"); params.put("categoryId", Long.toString(categoryId)); List<Book> results...