Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. How to call some Web API inside another Web API within same Project

How to call some Web API inside another Web API within same Project

Scheduled Pinned Locked Moved .NET (Core and Framework)
questioncsharpasp-netjsontutorial
6 Posts 5 Posters 39 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wahaj Khan
    wrote on last edited by
    #1

    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

    M Richard DeemingR J 3 Replies Last reply
    0
    • W Wahaj Khan

      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

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      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

      W 1 Reply Last reply
      0
      • M Mycroft Holmes

        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

        W Offline
        W Offline
        Wahaj Khan
        wrote on last edited by
        #3

        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

        P 1 Reply Last reply
        0
        • W Wahaj Khan

          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

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          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

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          1 Reply Last reply
          0
          • W Wahaj Khan

            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

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            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.

            Advanced TypeScript Programming Projects

            1 Reply Last reply
            0
            • W Wahaj Khan

              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

              J Offline
              J Offline
              jschell
              wrote on last edited by
              #6

              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.)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups