Trying to implement Scalar in a 9 aspcore app.
Doing the basics by using OpenApi. When i run it I see the UI but i dont see any of my methods. In the output window i see Request finished HTTP/2 GET https://localhost:7160/scalar/v1/scalar.aspnetcore.js - 404 0 - 38.9624ms
Which leads me to believe something is wrong with my code or Installation of scalar. Any Ideas?
Saclar should show the UI with my exposed API methods
Trying to implement Scalar in a 9 aspcore app.
Doing the basics by using OpenApi. When i run it I see the UI but i dont see any of my methods. In the output window i see Request finished HTTP/2 GET https://localhost:7160/scalar/v1/scalar.aspnetcore.js - 404 0 - 38.9624ms
Which leads me to believe something is wrong with my code or Installation of scalar. Any Ideas?
Saclar should show the UI with my exposed API methods
Share Improve this question edited 23 hours ago Zhi Lv 21.5k1 gold badge27 silver badges37 bronze badges asked Feb 18 at 4:46 Curtis ConnerCurtis Conner 1 New contributor Curtis Conner is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 2- can you share your configuration for Scalar here? to Understand what is the issue – Majid Commented 2 days ago
- default URL for OpenAPI documentation URL is this localhost:7160/openapi/v1.json – Majid Commented 2 days ago
2 Answers
Reset to default 0I guess you‘re calling /scalar/v1/
in your browser. Please try it again without the trailing slash /scalar/v1
.
Doing the basics by using OpenApi. When i run it I see the UI but i dont see any of my methods. In the output window i see Request finished HTTP/2 GET https://localhost:7160/scalar/v1/scalar.aspnetcore.js - 404 0 - 38.9624ms
The issue might relate the request URL.
By default, when using Scalar for interactive API documentation and to view the Scalar UI, the request URL is https://localhost:<port>/scalar/v1
: (you can find the port from Properties\launchSettings.json file)
To configure Scalar, we need to install the Scalar.AspNetCore
package, and the Program.cs file should like this: we need to add app.MapScalarApiReference();
:
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
app.MapScalarApiReference();
}
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
};
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.MapProductEndpoints();
app.Run();
Besides, please make sure you add the API controller or endpoints:
controller:
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
// GET: api/<ValuesController>
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/<ValuesController>/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
endpoints:
public class Product
{
public int ID { get; set; }
public string Name { get; set; }
}
public static class ProductEndpoints
{
public static void MapProductEndpoints (this IEndpointRouteBuilder routes)
{
var group = routes.MapGroup("/api/Product").WithTags(nameof(Product));
group.MapGet("/", () =>
{
return new [] { new Product() };
})
.WithName("GetAllProducts")
.WithOpenApi();
group.MapGet("/{id}", (int id) =>
{
//return new Product { ID = id };
})
.WithName("GetProductById")
.WithOpenApi();
Then the Scalar view as below: