Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Scalar

Scalar fournir une interface web pour tester notre service.

On l'active en installant une package Nuget.

Pour se faire lancer cette commande dans le dossier de votre projet

dotnet add package Scalar.AspNetCore
using Scalar.AspNetCore; // Ajoutez ce using


public class Program
{
    public static void Main(string[] args)
    {
        ...

        
        if (app.Environment.IsDevelopment())
        {
            app.MapOpenApi();
            app.MapScalarApiReference(); // Ajoutez cette ligne
        }

        ...
    }
}

Puis dans le Program.cs

Pour lancer automatiquement scalar on modifie le fichier Properties/launchSettings.json. On passera launchBrowser à true et on ajoutera launchUrl à http://localhost:5100/scalar/v1

{
  "$schema": "https://json.schemastore.org/launchsettings.json",
  "profiles": {
    "http": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "http://localhost:5100",
      "launchUrl": "http://localhost:5100/scalar/v1",
      ...
    }
  }
}