Can I customize the ServiceStack / metadata page?

I run my site behind the bootloader on a non-standard port. When loading the page / metadata, it has my public domain name, but the local port on which the application is hosted, which also leads to the breaking of links to different formats.

Example:

Is there any way to configure these links in the output? Also, is it possible to configure other text / css / etc on the page so that it can be changed to fit into the template that I use for the rest of my site?

+8
api servicestack metadata
source share
3 answers

v4 Update

v4 ServiceStack offers a number of new ways to customize embedded metadata pages:

Using a virtual file system

ServiceStack Virtual FileSystem returns by default (i.e. when there is no physical file) to search for embedded resource files inside the dll.

You can specify the amount and priority with which it looks using Config.EmbeddedResourceSources , which by default looks like this:

  • The assembly containing your AppHost
  • ServiceStack.dll

Now VFS allows you to completely replace the built-in ServiceStack metadata pages and templates with your own by simply copying the metadata or HtmlFormat template files that you want to configure and placing them in your folder at:

 /Templates/HtmlFormat.html // The auto HtmlFormat template /Templates/IndexOperations.html // The /metadata template /Templates/OperationControl.html // Individual operation template 

Register links on metadata pages

You can add links to your own plugins on metadata pages using:

 appHost.GetPlugin<MetadataFeature>() .AddPluginLink("swagger-ui/", "Swagger UI"); appHost.GetPlugin<MetadataFeature>() .AddDebugLink("?debug=requestinfo", "Request Info"); 

AddPluginLink adds links in the Plugin Links section, while AddDebugLink can be used by plugins that are available only during debugging or development.

Using metadata attributes

Many of the same attributes used by Swagger are also used on metadata pages, for example:

 [Api("Service Description")] [ApiResponse(HttpStatusCode.BadRequest, "Your request was not understood")] [ApiResponse(HttpStatusCode.InternalServerError, "Oops, something broke")] [Route("/swagger/{Name}", "GET", Summary = @"GET Summary", Notes = "GET Notes")] [Route("/swagger/{Name}", "POST", Summary = @"POST Summary", Notes = "Notes")] public class MyRequestDto { [ApiMember(Name="Name", Description = "Name Description", ParameterType = "path", DataType = "string", IsRequired = true)] [ApiAllowableValues("Name", typeof(Color))] //Enum public string Name { get; set; } } 

Old notes v3

ServiceStack The metadata page allows you to limit the configuration using EndpointHostConfig (where the entire configuration of ServiceStack is configured). For example. You can change the body HTML and operations page HTML in your AppHost with:

 SetConfig(new EndpointHostConfig { MetadataPageBodyHtml = "<p>HTML you want on the home page</p>", MetadataOperationPageBodyHtml = "<p>HTML you want on each operation page</p>" }); 

You can also add additional metadata documentation for each web service using the Request DTO attribute with the [Description] attribute, as is done in the MoviesRest movie example :

 [Description("GET or DELETE a single movie by Id. POST to create new Movies")] [RestService("/movies", "POST,PUT,PATCH,DELETE")] [RestService("/movies/{Id}")] public class Movie { public int Id { get; set; } public string ImdbId { get; set; } public string Title { get; set; } } 

And what does it look like on the MoviesRest / metadata page.

+9
source share

Look here for an understanding. This is not how to set up / metadata, but even more how to use XHTML to do the same with the Hypermedia APIs.

+1
source share

The Service Stack metadata page is fully customizable. You can use attributes to annotate certain properties or services by storing automatically generated content.

Content is delivered using built-in HTML templates, and it can also be replaced for detailed customization.

The metadata pages can be completely disabled, which I usually do using the following snippet.

 SetConfig(new HostConfig { EnableFeatures = Feature.All.Remove(Feature.Metadata) }); 

More information can be found in the Service Wack Wiki .

+1
source share

All Articles