title: Server side blazor app httpclient calls are not reaching my web API controller class
body: <p>I'm trying to create a multiplayer game using Blazor server-side app (RazorComponents) in .Net Core 3.0 preview. I have a SQL lite database and data access layer in my Server project to store the game information. I have a Controller class, also in the Server project, to return objects from the database using the data access layer. My cshtml page in the App project is making an api call (using injected HttpClient) trying to route to my controller, but it does not reach the server.</p>
  
  <p>I have been trying different Http client calls, but none seem to be reaching the controller. I feel like I'm missing something obvious, or configured something incorrectly. I don't have a solid Razor/MVC background, so this is a bit tough for me to troubleshoot. For testing, I'm trying to call a simple method that returns a string</p>
  
  <p>In App.Game.cshtml @functions { } section:</p>
  
  <pre><code>private async Task SaveGame()
  {
      var result = await Client.GetStringAsync("/api/Game/Test");
  }
  </code></pre>
  
  <p>In Server.Controllers.GameController:</p>
  
  <pre><code>public class GameController : Controller
  {
      [HttpGet]
      [Route("api/Game/Test")]
      public string Test()
      {
          return "test";
      }
  }
  </code></pre>
  
  <p>My Server.Startup file registers MVC and Http services like so:</p>
  
  <pre><code>// This method gets called by the runtime. Use this method to add services to the container.
      // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
      public void ConfigureServices(IServiceCollection services)
      {
          services.AddRazorComponents&lt;App.Startup&gt;();
          services.AddMvc();
  
          //Code I got from internet to register httpclient service
          if (!services.Any(x =&gt; x.ServiceType == typeof(HttpClient)))
          {
              // Setup HttpClient for server side in a client side compatible fashion
              services.AddScoped&lt;HttpClient&gt;(s =&gt;
              {
                  // Creating the URI helper needs to wait until the JS Runtime is initialized, so defer it.
                  var uriHelper = s.GetRequiredService&lt;IUriHelper&gt;();
                  return new HttpClient
                  {
                      BaseAddress = new Uri(uriHelper.GetBaseUri())
                  };
              });
          }
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IHostingEnvironment env)
      {
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
  
          app.UseStaticFiles();
          app.UseRazorComponents&lt;App.Startup&gt;();
          app.UseMvc(routes =&gt; { routes.MapRoute(name: "default", template: "{controller}/{action}/{id?}"); });
      }
  </code></pre>
  
  <p>When the SaveGame() method is called and client call is executed, I see this in the output:</p>
  
  <p>Microsoft.AspNetCore.Hosting.Internal.GenericWebHostService: Information: Request starting HTTP/1.1 GET <a href="http://localhost:59682/api/Game/Test" rel="nofollow noreferrer">http://localhost:59682/api/Game/Test</a><br>
  Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware: Information: Sending file. Request path: '/index.html'. Physical path: '{path to my game}.Server\wwwroot\index.html'</p>
  
  <p>So it seems like it isn't getting properly routed to the controller. I've been googling how other people have done this and it seems I'm doing it the right way. Anyone know what I'm missing?</p>
  
  <p>I've been following tutorials like these:
  <a href="http://learn-blazor.com/architecture/rest-api/" rel="nofollow noreferrer">http://learn-blazor.com/architecture/rest-api/</a>
  <a href="https://medium.freecodecamp.org/how-to-create-an-application-using-blazor-and-entity-framework-core-1c1679d87c7e" rel="nofollow noreferrer">https://medium.freecodecamp.org/how-to-create-an-application-using-blazor-and-entity-framework-core-1c1679d87c7e</a></p>