Radosław Maziarka
Radosław Maziarka

Reputation: 655

Service Stack - route attribute for complex request class

I want to use class OfferFilter to handle request for offers:

public class OfferFilter
{
    public int SortOrder { get; set; }
    public int PageSize { get; set; }
    public int PageNumber { get; set; }
    public string SearchQuery { get; set; }
    public bool ShowAllLanguages { get; set; }
    public int? SearcherSectorId { get; set; }
    public int? CountryId { get; set; }
    public int? RegionId { get; set; }
    public string City { get; set; }
    public int? AskingPriceFrom { get; set; }
    public int? AskingPriceTo { get; set; }
    public bool AskingPriceSelected { get; set; }
    public int? SalesRevenuesFrom { get; set; }
    public int? SalesRevenuesTo { get; set; }
    public bool SalesRevenuesSelected { get; set; }
    public int? IncomeFrom { get; set; }
    public int? IncomeTo { get; set; }
    public bool IncomeSelected { get; set; }
    public int? Age { get; set; }
}

How can I make a route attribute for that? Using POST would be easier but it will be GET request. Normal route string will be enormous and very error-prone.

Upvotes: 1

Views: 423

Answers (1)

mythz
mythz

Reputation: 143319

See the wiki page on Routing. You only need to register the path info for the Service, and you're still able to use any of the properties in the QueryString, e.g:

[Route("/offers/search")]
public class OfferFilter { ... }

Lets you call the above service with any combination, e.g:

/offers/search?city=XXX
/offers/search?city=XXX&Age=20
etc.

Upvotes: 1

Related Questions