Irish Yobbo
Irish Yobbo

Reputation: 433

ServiceStack OrmLite with multiple APIs (private and public)

We have a .net Core 3.1 MVC web application running with ServiceStack Ormlite 5.12. Currently we have a 'public' Open API for users who wish to access data programmatically. We use the following in our AppHost:

public class AppHost : AppHostBase
{

    public AppHost(IServiceProvider services, IWebHostEnvironment env)
        : base("My API", typeof(MyAPIService).Assembly)
    {
        _appServices = services;
        _env = env;
    }
    
    public override void Configure(Container container)
    {
        SetConfig(new HostConfig
        {
            ...
            HandlerFactoryPath = "/myapipath"
        });
        
        Plugins.Add(new OpenApiFeature
        {
            ...
        });
    }
}

And in our Web.config:

<configuration> 
      <location path="myapipath">
    <system.web>
      <httpHandlers>
        <add path="servicestack*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" />
      </httpHandlers>
    </system.web>
    <!-- Required for IIS7 -->
    <system.webServer>
      <modules runAllManagedModulesForAllRequests="true" />
      <validation validateIntegratedModeConfiguration="false" />
      <handlers>
        <add path="servicestack*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
      </handlers>
    </system.webServer>
  </location>
</configuration>

We have MyApp.ServiceModel and MyApp.ServiceInterface projects that are accessed from the https://{baseurl}/myapipath endpoint. This all works well so far.

We wish to keep the existing OpenAPI unchanged so that users don't need to change anything when updating to a new version. But we also want to add another API for use with an angular application, either by adding a separate endpoint for a 2nd API, or by filtering out what is visible in swagger with our existing API. Is it possible to add a 2nd API plugin with a different path that is separate from the existing API?

Upvotes: 1

Views: 50

Answers (1)

mythz
mythz

Reputation: 143319

There can be only one ServiceStack Open API Plugin registered which lists all publicly accessible APIs within an AppHost.

If you want to visually differentiate APIs you can Group related APIs with Tags:

[Tag("angular")]
public class MyRequest { ... }

Alternatively you can choose to Exclude Services from Metadata Pages with:

[ExcludeMetadata]
public class MyRequestDto { ... }

Upvotes: 1

Related Questions