Reputation: 2056
I am currently developing the ASP.NET Web API application and I am sending data to the server using the route parameters
and I also able to send the data in the body
like the in the JSON
format and send it to server.
Example:
http://localhost:59035/api/Authors/AddAuthors/MyTokenKey/AuthorName
And If I send the data in the body like this:
TokenKey=MyTokenKey&AuthorName=AuthorName
Than my server method is also called. In both way we can send the data.
So confusion is which is best way to send the data to server?
If we pass the data into route parameters
than it is visible to the others, it does not matter the our request is in which method, like POST
, GET
or anything else..
Good practice to call the Web API.
I also want to know which is good method to called the web API, from the server side
or from the client side
.
For example I created the Web API and hosted on the one domain
and I want to call that Web API
from another domain
. So which is better way to call the API from the client browser using AJAX
or call I have to call the Web API
from the Server.
Server
?Thanks.
Upvotes: 0
Views: 1136
Reputation: 5513
The only difference in passing parameters with GET
or POST
request is that GET
has limited parameter length, and we can consider POST
parameters to be unlimited. So it depends on you which method to choose.
What about calling API using AJAX or using another WebAPI. AJAX does not support cross-domain requests without additional operations. If you have your API deployed on domain1
and you want to call it using AJAX request from domain2
, then on domain1
you should define a cross-origin header which allows requests from domain2
.
If it is your API, you can define such a header. If it is a third party API, which does not allow cross-origin requests, you might need to call it from your own WebAPI.
Upvotes: 1