documentation/integrations/aspnetcore/legacy-integration.md
This guide explains how to integrate API Reference into .NET Framework and .NET Core projects using static assets.
Swashbuckle.AspNetCore.SwaggerGen or NSwag.AspNetCore)public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
// Using Swashbuckle
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
});
// OR using NSwag
services.AddOpenApiDocument();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// Enable the endpoint for generating the OpenAPI documents
app.UseSwagger();
// Required for serving static Scalar files
app.UseStaticFiles();
// Other middleware
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
Create the following folder structure:
wwwroot/ (or your static files directory)
└── scalar/
├── index.html
└── scalar.config.js
Create index.html in the wwwroot/scalar directory with:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>API Reference</title>
</head>
<body>
<div id="app"></div>
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
<script src="./scalar.config.js"></script>
</body>
</html>
Create scalar.config.js in the same directory:
Scalar.initialize({
selector: "#app",
url: "/swagger/v1/swagger.json", // Adjust this URL to match your OpenAPI document path
theme: "moon" // Other configuration
});
After starting your application, the API Reference will be available at:
http://localhost:<port>/scalar/index.html
To use a specific version instead of the latest, specify the version in your HTML:
<script src="https://cdn.jsdelivr.net/npm/@scalar/[email protected]"></script>
app.UseStaticFiles() is present in your middleware pipelineFor more configuration options, refer to the official Scalar configuration documentation.