.Net Core API in Google Cloud Function

I am looking at the beta version of running .net core api in Google Cloud Functions.

https://cloud.google.com/functions/docs/quickstart-dotnet

I have a rest api running in AWS lambda and i am planning to to migrate to Google Cloud Functions.

I want to understand if we can run a full fledged api with multiple endpoints like api/method1 , api/method2 etc like lambda or is it not possible right now in google cloud function. Examples showed in the page just listens to a single url.

I also tried adding the

[FunctionsStartup(typeof(Startup))]

And in the startup, I added the controllers like below, but routing to the controller is not happening

public override void ConfigureServices(WebHostBuilderContext context, IServiceCollection services)
    {
        services.AddControllers();
    

Can someone please clarify?

Upvotes: 2

Views: 1340

Answers (2)

Chaim Klar
Chaim Klar

Reputation: 300

@karthick, maybe check this out

see this article from google cloud "Exposing ASP.NET Web API using .NET Core with Cloud Endpoints" https://cloud.google.com/community/tutorials/exposing-aspnet-webapi-using-dotnetcore-with-cloud-endpoints

it does seem like all the api endpoints will automatically be exposed when following those steps.

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1500923

The Functions Framework expects a single function to be registered. That function could itself perform additional routing based on the URI, and it's possible that you could use a lot of the built-in ASP.NET Core routing to do that, but it's not a scenario we're investing in right now. It sounds like you logically want multiple functions - so I'd suggest deploying it as multiple functions. Those multiple functions could still all be present in the same project if that's convenient for you - you'd just specify different entry points when you deploy.

Alternatively, you could use a regular ASP.NET Core app and deploy that to Cloud Run to retain the benefits of serverless pricing etc, if you only want a single deployment.

Upvotes: 1

Related Questions