I understanding now, how the Magnolia works. I writing REST Endpoint for Magnolia Content App in Java. My Content App is Categories – App and it looks like this:
- cat-1: cat-1, cat-4; - cat-3: ""
My task is, to define a REST endpoint for the Categories app in Java, which delivers the subcategories based on a passed category name and displays them in a component. For example: if you enter “GET “cat-1″” then you get a JSON-Array [“cat-1”, “cat-4”]
I want to connect java-code with my endpoint. I have created the ‘testendpoint’ endpoint but have problem to union my java-code with the get request in browser. http://localhost:8080/.rest/testendpoint/20
Java-Code:
@Api("/testendpoint") @Path("/testendpoint") class EndpointService { @GET @Path("/testendpoint/{endpointId}") @Produces(MediaType.APPLICATION_JSON) public String getResponse( @QueryParam("endpointId") String endpointId) throws JsonProcessingException { JsonObject json = new JsonObject(); json.addProperty("Mobile", endpointId); json.addProperty("Name", "Fake name"); return json.toString(); } }
and in repository “src/main/resources/rest-endpoints” I have yaml-file:
class: info.magnolia.rest.service.node.definition.ConfiguredNodeEndpointDefinition implementationClass: com.raysono.endpoints.EndpointService
maybe I forgot to connect something else. please help to check and customize request
Advertisement
Answer
This should work already using the default endpoint provided by Magnolia, using url http://your_instance/.rest/nodes/v1/category/cat-1?depth=2
(assuming the path /cat-1/cat-4
exists). However you get a lot of unnecessary properties with it as well.
Better option is to configure delivery end point as mentioned in documentation.
Possibly yet better option is to have GraphQL module installed and use GraphQL to define and get exactly what you need.
Either of those options is faster and easier to maintain in the long run than writing your own endpoint.