Exemplos
Abaixo temos alguns exemplos de implementação da integração com AnnA Web Services
[HttpPost] public HttpResponseMessage V3([FromBody] dynamic json) // Do not use dynamic type, this is for example purposes only { var containers = new List<object> { new { Type = "MESSAGE", Phrase = json.value, }, };
var response = new HttpResponseMessage(HttpStatusCode.OK); response.Headers.Add("Authorization", Request.Headers.Authorization.ToString());
var responseContent = new { success = true, message = "", containers };
response.Content = new StringContent(JsonConvert.SerializeObject(responseContent), Encoding.UTF8, "text/plain");
return response; }
[HttpPost] public IActionResult V3(dynamic json) { HttpContext.Response.Headers.Authorization = HttpContext.Request.Headers.Authorization;
var containers = new List<object> { new { Type = "MESSAGE", Phrase = json.value } };
return Ok(new { success = true, message = "", containers }); }
@RestController@RequestMapping("/api/anna-ws")public class AnnAWebServiceController { @PostMapping("v3") public ResponseEntity<Object> v3(@RequestHeader("Authorization") String authorization, @RequestBody HashMap<String, Object> json) { ArrayList<Object> containersList = new ArrayList<>(); containersList.add(new Object() { public final String Type = "MESSAGE"; public final String Phrase = json.get("value").toString(); });
Object response = new Object() { public final boolean success = true; public final String message = ""; public final ArrayList<Object> containers = containersList; };
HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setBearerAuth(authorization); httpHeaders.setContentType(new MediaType("application", "json", StandardCharsets.UTF_8));
return new ResponseEntity<Object>(response, httpHeaders, HttpStatus.OK); }}