Home > front end >  HttpRepl, navigation command "ls" does not show available endpoints for the current URL pa
HttpRepl, navigation command "ls" does not show available endpoints for the current URL pa

Time:09-23

I am working through the Microsoft Learn tutorials to "Create a web API with ASP.Net Core".

Under the heading, "Build and test the web API", at instruction (5) I am getting a response, "Unable to find an OpenAPI description".

For step (6) when executing the "ls" command I get the response, "No directory structure has been set, so there is nothing to list. Use the 'connect' command to set a directory structure based on an OpenAPI description". I have tried the "connect" command suggested here and have tried "dir" as an alternative to "ls".

I can successfully change directories in step (7) and execute the GET request for step (8) and receive the expected reply. However, it really bothers me the "ls" command is not working here and seems like an important function of the httprepl tool.

How can I get the "ls" command to work here or tell me why does it not work?

C:\Users\jamie\source\repos\Learn\ContosoPizza>httprepl http://localhost:5000
(Disconnected)> connect http://localhost:5000
Using a base address of http://localhost:5000/
Unable to find an OpenAPI description
For detailed tool info, see https://aka.ms/http-repl-doc

http://localhost:5000/> ls
No directory structure has been set, so there is nothing to list. Use the "connect" command to set a directory structure based on an OpenAPI description.       

http://localhost:5000/>

httprepl GitHub repo and MS Docs page

CodePudding user response:

In step 5 you get "Unable to find an OpenAPI description", which means the HttpRepl tool can't find the swagger endpoint, and therefore the ls command wont work.

Specifying your OpenAPI description

To find out which endpoint swagger is using, open the file Startup.cs and search for .UseSwaggerUI. You should find this block of code:

if (env.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
    app.UseSwagger();
    app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebAPI v1"));
}

Use the endpoint you find and run the tool like this:

httprepl http://localhost:5000 --openapi /swagger/v1/swagger.json

Ignoring your enviroment

If that doesn't work, then you are not running your Web API in a development environment. So either use a development environment, or uncomment the if-statement while testing (to setup your environment for development - see below):

//if (env.IsDevelopment())
//{
    app.UseDeveloperExceptionPage();
    app.UseSwagger();
    app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebAPI v1"));
//}

Remember to restore the code you uncommented, if any, before you deploy to production.

Changing your environment

The profile your Web API is using, is specified in the file Properties\launchSettings.json. Open the file and search for ASPNETCORE_ENVIRONMENT. Then change the instances you find to:

"ASPNETCORE_ENVIRONMENT": "Development"

If this doesn't work, or the instances were already set to "Development", it means that you are not using any of the profiles specified in your launch settings. If no profile is used, ASPNETCORE_ENVIRONMENT defaults to "Production". When using the dotnet run command, the --launch-profile parameter lets you specify which profile to use:

dotnet run --launch-profile "name_of_profile"

As a last resort you can set the environment variable ASPNETCORE_ENVIRONMENT in the shell you are using, before you run the command dotnet run:

Bash
export ASPNETCORE_ENVIRONMENT=Development

CMD
set ASPNETCORE_ENVIRONMENT=Development

PowerShell
$env:ASPNETCORE_ENVIRONMENT='Development'

To learn more about setting up the environment or profile

Managing Production and Development Settings in ASP.NET Core
Use multiple environments in ASP.NET Core

  • Related