'HttpGet route not found

I have built a controller. For some unknown reason the end point is not reached. Unfortunately I do not understand why.

[Route("api/realestates")]
[ApiController]
public class RealEstateController : CustomControllerBase<RealEstateController>
{
    [HttpGet]   // not reached
    public async Task<IResult<List<RealEstateListDTO>>> GetAll()
    {
        //[...]
    }
}

If i change the route from controller to api/realestate or from Get-method to [HttpGet("all")] it works. In the CustomControllerBase are no routes defined.

I used autogenerated Swagger to test the route. I have intentionally overwritten the route. The route works, if i don't start with debugger. If i uses the Debbuger, Swagger shows the route but i get the index.html-Fallback.



Solution 1:[1]

check your endpoint in postman or browser and check your startup has something like this

services.AddControllersWithViews 

or

 services.AddControllers

and your customecontroller must inherits ControllerBase

Solution 2:[2]

You’re calling ‘api/realestate’

But in the attribute you’ve defined ‘api/realestates’

So try with the ‘s’ at the end

If you want the route to match the controller name (minus “Controller”). You should change your route attribute to -

[Route("api/[controller]")]

Solution 3:[3]

You can use this kind of algorithm. First sort the list using any sorting algorithms, let us use bubble sort for now. Then count the frequency of all elements and store it in a dictionary and then and convert it back into a nested list. So you can do something like this:

def bubble_sort(ls):
    swapped = True
    while swapped:
        swapped = False
        for i in range(len(ls) - 1):
            if ls[i] > ls[i + 1]:
                # Swap the elements
                ls[i], ls[i + 1] = ls[i + 1], ls[i]
                swapped = True
    return ls

def nest(ls):
    ls2 = {}
    res = []
    for i in ls:
        if i in ls2:
            ls2[i] += 1
        else:
            ls2[i] = 1
    i = 0
    while i<len(ls):
        res.append([ls[i]]*ls2[ls[i]])
        i+=ls2[ls[i]]
    return res

print(nest(bubble_sort(['apple', 'grape', 'orange', 'orange', 'apple', 'grape', 'apple'])))

Solution 4:[4]

To sort this list you can run this code:

list_1 = ['apple', 'grape', 'orange', 'orange', 'apple', 'grape', 'apple']
list_1.sort()

dictionary = {}
for item in list_1:
    if item not in dictionary:
        dictionary[item] = 1
    else:
        dictionary[item] += 1

list_1 = []
for word in dictionary:
    list_2 = [word]*dictionary[word]
    list_1.append(list_2)

print(list_1)

This outputs

[['apple', 'apple', 'apple'], ['grape', 'grape'], ['orange', 'orange']]

The second line of code is optional, you can remove it if you don't need the last list to be in alphabetical order.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mahdi
Solution 2
Solution 3 Divyessh
Solution 4 Unnamed