Skip to content

0.4.0

Compare
Choose a tag to compare
@swhitty swhitty released this 06 Mar 04:52
· 662 commits to main since this release
e5d510c

Several enhancements have been made to HTTPRoute that enable fine grained pattern matching of requests.

Query items can now be matched:

await server.appendRoute("GET /meal?side=fish", to: .file(named: "meal-fish.json"))
await server.appendRoute("GET /meal?side=chips", to: .file(named: "meal-chips.json"))

HTTP headers can also be matched:

let json = HTTPRoute("*", headers: [.contentType: "application/json"])
let xml  = HTTPRoute("*", headers: [.contentType: "application/xml"])

await server.appendRoute(json, to: .file(named: "sample.json"))
await server.appendRoute(xml, to: .file(named: "sample.xml"))

And request body can also be matched:

public protocol HTTPBodyPattern: Sendable {
  func evaluate(_ body: Data) -> Bool
}

Darwin platforms can pattern match a JSON body with an NSPredicate:

let route = HTTPRoute("POST *", body: .json(where: "food == 'fish'"))
{"side": "chips", "food": "fish"}