I have a controller like this:
[ApiController]
[Route("[controller]")]
public class EmployeeController : ControllerBase
{
[HttpGet("[action]/")]
public async Task<IActionResult> GetAll()
{
return Ok(await _employeeService.GetAllEmployees());
}
[HttpDelete("[action]/{id}")]
public async Task<IActionResult> Delete(int id)
{
await _employeeService.DeleteEmployee(id);
return Ok();
}
}
Through Swagger, everything works great, all requests are detected. But if you enter a direct request, in my case: https://localhost:7080/Employee/Delete/3, then 405 is returned. I read on the Internet, I met a situation, only with deployed APIs, but it doesn’t even work for me on a local host. What could be missing?
EDIT Also trying to use it in TypeScript like this:
async function deleteById(url: string, id: number) {
return await fetch(url + id.toString(), { method: 'DELETE', }).then((response) => {
if (!response.ok)
console.log(response);
else
return response.json();
});
}
deleteById("https://localhost:7080/Employee/Delete/", id).then((json) => {
console.log(json);
});