package com.progress.fathom.sample.webapp; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import com.progress.fathom.Body; import com.progress.fathom.Description; import com.progress.fathom.FathomAPIServletHandler; import com.progress.fathom.PathParam; import com.progress.fathom.QueryParam; import com.progress.fathom.RequestException; import com.progress.fathom.RequestMapping; import com.progress.fathom.RequestMethod; import com.progress.fathom.RequiredResourcePermission; import com.progress.fathom.Since; import com.progress.isq.ipqos.resources.security.SecurityBean; /** * this is sample REST API handler based on the OpenEdge Management REST * annotation mapping * */ public class RestExample extends FathomAPIServletHandler { @Description("Example REST get request") @RequestMapping(path = "/get/{id}", method = RequestMethod.GET) @Since("11.7") @RequiredResourcePermission(grantName = SecurityBean.SECURITY_ROOT, action = SecurityBean.ACTION_READ) public Object getSample(@PathParam("id") String id, @QueryParam("q") String queryString) throws RequestException { // object mapper is from jackson JSON library ObjectMapper mapper = new ObjectMapper(); // this creates a simple JSON response using the values from the URL // mapped back into the object as JSON object properties ObjectNode response = mapper.createObjectNode(); response.put("id", id); return response; } @Description("Example REST POST request") @RequestMapping(path = "/post/{id}", method = RequestMethod.POST) @Since("11.7") @RequiredResourcePermission(grantName = SecurityBean.SECURITY_ROOT, action = SecurityBean.ACTION_READ) public Object postSample(@PathParam("id") String id, @Body ObjectNode body) throws RequestException { // object mapper is from jackson JSON library ObjectMapper mapper = new ObjectMapper(); // this creates a simple JSON response using the values from the URL // mapped back into the object as JSON object properties, along with the // content of the request body // from the POST ObjectNode response = mapper.createObjectNode(); response.put("id", id); response.put("request", body); return response; } } |