Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

We have a web api which is built in separate solution altogether. I want to consume that in my project. Can you please help me how to call this external web api from jquery ajax. Web API is hosted within the same intranet domain.

Thanks,
Nilesh

What I have tried:

I know how to call it when it is within the same project but not sure when it is entirely in different solution.
Posted
Updated 23-Jan-19 23:59pm
v2

When you say you know how to call it when it is in within the same project, it means you already know how to do it. There is absolutely no difference in the procedure of calling api through ajax. The only difference in your case will be, the API will have an address.
for ex it will be like https://www.myawesomeapi.com/api/getmethod this will be your url parameter in your ajax call.
you can post the code where you have called the api when it is within the same project.
That will help to resolve the issue here.
 
Share this answer
 
You know how to call api that's cool.

Please follow below steps for calling a api as a generic one.

1.Publish your webapi in any server or your local server
2.you will get the path of the api from it right.
eg:->
https://www.api.com/api/methodname

3.Now go to your project from where you want to call api.
a.you know the path of the api.so declare that root path as globally
eg:-> ServerPath='https://www.api.com/api'
b.And when you are calling api just put serverPath i.e. globally declared with your api method name
eg:-> serverPath + '/MethodName'
in your ajax call url.
5.And with this you can call webapi project method and you can do whatever you want.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900