0

I'm trying to configure a transformer for an endpoint with parameters.

I successfully configured transformers for endpoints that don't include any parameters. But it seems that when I try to do the same for Resource with parameters it won't work.

This is how I configure transformer:

var getExampleData: Resource { return resource(exampleDataEndpoint) }
configureTransformer(getExampleData) {
            try jsonDecoder.decode(ExampleDataResponse.self, from: $0.content)
}

And this is how I send the request:

Api.getExampleData.withParam("foo", "bar").addObserver(self).loadIfNeeded()

I get the response but it never goes thru the transformer pipeline.

Response:  200 ← GET http:example.com/enpoint?foo=bar
Siesta:pipeline │ [thread ᎠᏔᎼᎼ]  └╴Response after pipeline: success: 28 bytes

EDIT

Tested the .withParam() method on transforms that work fine and it seems like the URL has to be the same in order to Siesta transformers work, it's a bummer.

Omega
  • 61
  • 5

1 Answers1

0

Different query strings mean different URLs, and different URLs mean different Siesta resources:

Note that “URL” includes the whole URL: protocol, host, path, and query string. It does not include headers, however. Different query strings? Different resources. http vs https? Different resources.

Thus:

let resource0 = Api.getExampleData
let resource1 = Api.getExampleData.withParam("foo", "bar”)
resource0 == resource1  // → false

So when you do this:

configureTransformer(getExampleData) { ... }

…that applies only to getExampleData, not to any variations with different params.

If you want configuration to apply to all resources that share a path, match on the path:

configureTransformer("/example/path") { ... }
Paul Cantrell
  • 9,175
  • 2
  • 40
  • 48