Decoding query params

Hi there!

I need to decode query parameters from queries like:

  • localhost?filter[name]=awesomeVapor&filter[description]=Swift
  • localhost?filter[name][eq]=awesomeVapor&filter[description][neq]=Swift

into content struct

struct IndexRequest: Content {
    var name: Filter<String>?
    var description: Filter<String>?

struct Filter<T: Content>: Content {
    var value: T
    var filterOperator: Operator
    init(value: T, filterOperator: Operator = .equals) {
        self.value = value
        self.filterOperator = filterOperator
    enum Operator: String, Content {
        case equals = "eq"
        case notEquals = "neq"

Can I do it painlessly?

1 Like

Just posting because I find the question interesting and would like to know the answer too.