Siesta Service configureTransformer for URL decode models based upon parameters

36 Views Asked by At

I have an endpoint which supports post requests. The URL is the same for all requests but the parameters will be different for each request. It is basically a free-form query service when the client can formulate the query and fields that will be returned in the response. I would like to be able to define methods on the service which will represent specific queries and a model for each query. But I am uncertain as to how I would go about configuring the transformer for each "query based" endpoint.

Is there a way to accomplish this or is it best to simply work with a json dictionary? Thanks...

1

There are 1 best solutions below

0
On

I think that I found the solution to my problem and it was rather simple. It was just a matter of building the resource and supplying it to configureTransformer.

    func getUserIds() -> Request {
        let res = resource(endPoint)
            .withParam("query", "SELECT id FROM users where status='Active'")

        configureTransformer(res) {
            try self.jsonDecoder.decode(UserIdResponse.self, from: $0.content)
        }

        return res.request(.post)
    }