Kyeotic
Kyeotic

Reputation: 19847

Route Attribute Ignored

According to multiple documentation sources, routes can be defined as attributes on the DTO. I have the following DTOs (the last one is in a different file):

[Route("/hdos", "GET")]
public class GetHdos
{
    public bool IncludeAdminUsers { get; set; }
}

[Route("/hdos/{Id}", "GET")]
public class GetHdo
{
    public Guid Id { get; set; }
}

[Route("/hdos/{HdoId}/facilities", "GET")]
public class GetHdoFacilities
{
    public Guid HdoId { get; set; }
}

Housed by the following services (the last one is in a different file):

public object Get(GetHdos request)
{
    return _hdos.GetAll(request.IncludeAdminUsers);
}

public object Get(GetHdo request)
{
    return _hdos.GetById(request.Id)
}

public object Get(GetHdoFacilities request)
{
    return _hdos.GetFacilities(request.HdoId);
}

A call to any of

/hdos
/hdos/a82b955195e34bfda2fdde7da68f8992
/hdos/a82b955195e34bfda2fdde7da68f8992/facilities

Returns Method not supported. But if I call them as the class name, the routes are hit. Is there something I am missing? Do I need to activate these routes in the AppHost somehow?

Upvotes: 1

Views: 180

Answers (1)

Kyeotic
Kyeotic

Reputation: 19847

It looks like ServiceStack maps your route differently for the REST and HTTP types. I didn't mention in the question that I was calling Json/syncreply/hdos Because I thought the Json/syncreply was part of every call. I was wrong. If you do that, it will look for the DTO class name as the route.

To use the Route declared on the DTO as an attribute, you just call the route, leaving off the json/syncreply. The inverse is not directly stated in the documentation, but I was confused nonetheless.

Upvotes: 2

Related Questions