1
Apicontroller
[Produces("application/json")]
[Route("api/[controller]")]
public class ClienteController : Controller
{
private IClienteRepository _ClienteRepository;
public ClienteController(IClienteRepository clienteRepository)
{
_ClienteRepository = clienteRepository;
}
[HttpPost]
public IEnumerable<Cliente> Get()
{
return _ClienteRepository.Get(x => x.ClienteId > 0);
}
}
Stratup
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<IClienteRepository, ClienteRepository>();
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseMvc();
}
}
Launchsettings.json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:52676/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/cliente",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Safra.AberturaDeContas.Api": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/cliente",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:52677/"
}
}
}
Error while climbing the api by accessing http://localhost:52676/api/client:
This localhost page can’t be found
It seems your controller has no Get method, only one Post, and via browser, you do a GET.
– Lucas Brogni
Using Postman with the Post method I’m also not getting the return
– Nicola Bogar
the status code is being 200 ?
– Lucas Brogni
using the URL = http://localhost:52676/Client/Get clients and http://localhost:52676/api/Client/Get clients, Return = 404 Not Found
– Nicola Bogar
I got @Lucas Brogni, I used the URL: http://localhost:52676/Client/Get clients and I memorized my method
[HttpPost]
 [Route("/Cliente/ObterClientes")]
 public IEnumerable<Cliente> ObterClientes()
 {
 return _ClienteRepository.Get(x => x.ClienteId > 0);
 }
– Nicola Bogar