AliSoftware / OHHTTPStubs

Stub your network requests easily! Test your apps with fake network data and custom response time, response code and headers!
MIT License
5.03k stars 601 forks source link

enhancement - Wildcard in path #235

Closed Reedyuk closed 7 years ago

Reedyuk commented 7 years ago

Hi, I cannot seem to find a way to match my urls with a wildcard. For example: /hello/9ff49154-9a63-460a-b63a-50b74ded4161/anotherMethod

I would usually pass something like: /hello/*/anotherMethod

To match the method, as this is how the api structure is setup.

AliSoftware commented 7 years ago

Hi

OHHTTPStubs doesn't contain any URL templating logic. Only simple matchers like isScheme(…), isHost(…), isPath(…) and similar are provided.

Instead you can provide your own matcher quite easily, for example use:

stub(condition: { req in 
  guard let path = req.url?.path else { return false }
  return path.hasPrefix("/hello/") && path.hasSuffix("/anotherMethod")
}, response: …)

For advanced matching stuff like using a wildcard * or similar, you could use https://github.com/Kyle/URITemplate.swift for example.

See also #125.

AliSoftware commented 7 years ago

I'll close this issue as a duplicate of #125, please continue any discussion there.