REST Module
Exposes custom REST APIs using JAX-RS (Java API for RESTful Web Services).
- Allow external systems to interact with Liferay (e.g., mobile apps).
- Build headless applications.
Implementation
Section titled “Implementation”Create the Module
Section titled “Create the Module”blade create -t rest book-rest-apiDefine a REST Endpoint
Section titled “Define a REST Endpoint”@Path("/books")@Produces(MediaType.APPLICATION_JSON)@Consumes(MediaType.APPLICATION_JSON)public class BookResource { @GET public List<Book> getBooks() { return BookService.getBooks(); // Your service logic }
@POST public Response addBook(Book book) { BookService.addBook(book); return Response.ok().build(); }}Test the API
Section titled “Test the API”curl http://localhost:8080/o/book-rest-api/booksUse Cases
Section titled “Use Cases”- Mobile Apps: Fetch Liferay data via REST.
- Third-Party Integrations: Sync data with CRM/ERP systems.