How to call some Web API inside another Web API within same Project
-
Hi I am looking for some solution to call an API method inside another API. I am working on DotNet EF Core Web API project. I have implemented several Web APIs within the project....I can call some Web API Post method by defining data for the insertion....The data is inserted successfully in the respective table related to API. What I want to do is that after successful insertion of data , logging information is need to be added in some table related to other API in same project/solution. The question is how can we pass data from first API to other to solve this ? OR How can we invoke Post method of other API from first API to do this? Any Suggestion plz Thanks
-
Hi I am looking for some solution to call an API method inside another API. I am working on DotNet EF Core Web API project. I have implemented several Web APIs within the project....I can call some Web API Post method by defining data for the insertion....The data is inserted successfully in the respective table related to API. What I want to do is that after successful insertion of data , logging information is need to be added in some table related to other API in same project/solution. The question is how can we pass data from first API to other to solve this ? OR How can we invoke Post method of other API from first API to do this? Any Suggestion plz Thanks
I would think logging of data transactions would be performed at the database level!
Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP
-
I would think logging of data transactions would be performed at the database level!
Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP
Sorry, we need to do this at Web API level. The thing is that if some record is entered, updated or deleted using some API, another record needs to be added in some table using other API at the same time Thanks
-
Hi I am looking for some solution to call an API method inside another API. I am working on DotNet EF Core Web API project. I have implemented several Web APIs within the project....I can call some Web API Post method by defining data for the insertion....The data is inserted successfully in the respective table related to API. What I want to do is that after successful insertion of data , logging information is need to be added in some table related to other API in same project/solution. The question is how can we pass data from first API to other to solve this ? OR How can we invoke Post method of other API from first API to do this? Any Suggestion plz Thanks
Either create an instance of the controller class and call the action method directly, or have the API method pass the call through to another class which implements the logic, and call that from both.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Sorry, we need to do this at Web API level. The thing is that if some record is entered, updated or deleted using some API, another record needs to be added in some table using other API at the same time Thanks
Wahaj Khan wrote:
Sorry, we need to do this at Web API level
That may not strictly be true though. You might think that you want to do this via Web API, but that is not the same as actually needing to do this via Web APIs. The proposal here is not a good idea because you have introduced a transactional dependency into your API at this point. Suppose that the API that deletes the record happens successfully, and then calls the second API, which is down. What are you going to do at that point? Undelete the record? If you are logging things happening at the database, let the database take care of the logging. Alternatively, you need to consider how to cope with failure conditions and look at techniques such as event passing, retry mechanisms, queues and the likes to see if they can help you in this situation. Bottom line - your current design is borked if it's only relying on happy path scenarios.
-
Hi I am looking for some solution to call an API method inside another API. I am working on DotNet EF Core Web API project. I have implemented several Web APIs within the project....I can call some Web API Post method by defining data for the insertion....The data is inserted successfully in the respective table related to API. What I want to do is that after successful insertion of data , logging information is need to be added in some table related to other API in same project/solution. The question is how can we pass data from first API to other to solve this ? OR How can we invoke Post method of other API from first API to do this? Any Suggestion plz Thanks
Wahaj Khan wrote:
The question is how can we pass data from first API to other to solve this ?
I can only suppose that you think that you are going to do this via the following 1. First API does just the main part of the functionality 2. That API exits (in some meaning of that word). 3. The log happens which invokes another API call. Can you make that happen? Yes I believe so. It involves delving into some of the semantics of how it handles some of a Web call for you. For example you can intercept errors. Should you do it? If there is only one method that needs this then no. Just do it in the same code that does the first functionaliy. If you want to do it with more than one API call, then start figuring out how the call flow is actually handled before it gets to your code and after it leaves your code. You should keep in mind that doing it this way ADDS complexity. That is because when something goes wrong it can interfere with stuff in unexpected ways (for example how you handle errors from the second call.)