0
I have a web application mvc and in it I have an action that should pass a parameter to a REST service. How do I pass a parameter to a REST service. I know that I will have to implement an Httppost, but how? Does anyone know a Tuto that can help us?
EDIT1
The following. Imagine a parent company with 7 stores. Each store with its team of sellers. A customer arrives at this store and makes a huge purchase. It is very common to sell more than R $ 5.000,00. In this sale there are several items. Well, let’s say a certain customer bought inputs, vaccines and so on and gave you 120,000. Since he has the money, he asks for a long term (until the harvest, maybe) a discount. It turns out that this discount is beyond the seller’s ability to grant, so he starts the guy right above him, who’s usually at the head office. How does he do it? Changing a flag in the BD(FLAG_LIBERACAO) from 1 to 0. This is when the system will act. This change the company developers will do (system done in Clarion/Interdev). What happens is, when the customer requests the discount, the seller clicks on a button that changes the Flag and already sends to the service (here my system enters) the Request (I put OK/Deny) but it can be anything. Then the service picks up this newly arrived information and fires a Push Notification(PN). And each manager/director receives and does what he has to do. There’s a rule for everyone to receive, but that’s something else and I’m already on it. I hope I’m clear, but if there’s any doubt, I’m here to answer.
EDIT2
I set up my API like this:
public class GetValueLiberacao
{
[Route("api/postvalueliberacao/{value}")]
[AcceptVerbs("Post")]
public HttpResponseMessage PostValueLiberacao([FromBody] string value)
{
try
{
if (value == "Ok")
{
Task t = new Task(async () =>
{
await SenderMessage();
});
t.Start();
}
var response = new HttpResponseMessage(HttpStatusCode.Created)
{
Content = new StringContent("OK")
};
return response;
}
catch(Exception ex)
{
var response = new HttpResponseMessage(HttpStatusCode.Created)
{
Content = new StringContent("Falha \n" + ex.Message)
};
return response;
}
}
public static async Task<IFCMResponse> SenderMessage()
{
FCMClient client = new FCMClient("AAAA0myCZjE:APA91bETPO0K3EtgBhHz_gMXDtBTiQrCsFaOW8wmFxbk5XvYhxTRIW9ZQR_mxNU8ThWe0d0A40JzG-Up_P2qyCw9hf6DrrRJfpynRIpnv_8FjIk3BsElnBuRenOi0h2r_h7Bv_"); //as derived from https://console.firebase.google.com/project/
var message = new Message()
{
To = "APA91bGmgZnr2YMolubwS7c_e6AAkbVj6ga83lSHLo31FRUoom3iuS73PR1Bo6-iJEZWA88Xom7SWMrBK7edS6xVoe0kHdoIEowye4dsKXdtHdjd60_QEYcBkIi9QLyP7ZX6qdfdj", //topic example /topics/all
Notification = new AndroidNotification()
{
Body = "Solicitação de Novo Desconto",
Title = "Desconto",
}
};
//CrossBadge.Current.SetBadge(1, "Teste");
var result = await client.SendMessageAsync(message);
return result;
}
}
In case I get OK in the parameter, I then trigger the Push Notification. Now I am working on the consumption and sending of the parameter, from another application. The question now would be the controller, as it would be, since it is for her that the program will send the data. I have not yet assembled. I just made this method and need to assemble the controller that will make all this happen. I will need to Enablecors?
EDIT3 I made my controller like this:
[RoutePrefix("api/postvalueliberacao")]
public class GetLiberaItensController : ApiController
{
AutorizadorContext contexto = new AutorizadorContext();
GetValueLiberacao libitens = new GetValueLiberacao();
[Route("{value}")]
[AcceptVerbs("Post")]
public HttpResponseMessage GetLiberaItens(string value)
{
return libitens.PostValueLiberacao(value);
}
}
I’ll start filling out. First on Postman and then on my app.
you described what the application has to do...you want to actually is to create the api ? It is very wide and will certainly be closed... consume an api ? need her documentation, or at least know how it works...
– Rovann Linhalis
It is not creating the API, but passing a parameter to a service. That’s it. I only developed my rule to make it clearer. I just want to know how I send a parameter, a string, a bool, anything to a REST.
– pnet
so...you need to know how this api normally gets it in the url, but you can get it in header or content as well
– Rovann Linhalis
Like this: http://meusite.com.br/autoriza/api/getparametro/{value}. As sending a desktop a parameter to get the value of my URL.
– pnet
the api is yours ? show her code, route...controller...qlqr thing
– Rovann Linhalis
I’m still doing and it’s one of the doubts when the subject is post, but I’m going to po this way:
[Route("api/getliberaitens/{value}")]
 [AcceptVerbs("Post")]
 public string PostValueLiberacao([FromBody] string value)
 {???????????????????
 return value;
 }
– pnet
With the API above, running this on Postman, it should work?
http://www.inetglobal.com.br/autorizador/api/postvalueliberacao/Ok
– pnet
Let’s go continue this discussion in chat.
– Rovann Linhalis