All Verbs | /query/customers |
---|
import Foundation
import ServiceStack
public class QueryCustomers : QueryDb<Customer>
{
public var ids:[String]
public var countryStartsWith:String
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case ids
case countryStartsWith
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
ids = try container.decodeIfPresent([String].self, forKey: .ids) ?? []
countryStartsWith = try container.decodeIfPresent(String.self, forKey: .countryStartsWith)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if ids.count > 0 { try container.encode(ids, forKey: .ids) }
if countryStartsWith != nil { try container.encode(countryStartsWith, forKey: .countryStartsWith) }
}
}
// @DataContract
public class Customer : Codable
{
// @DataMember
public var id:String
// @DataMember
public var companyName:String
// @DataMember
public var contactName:String
// @DataMember
public var contactTitle:String
// @DataMember
public var address:String
// @DataMember
public var city:String
// @DataMember
public var region:String
// @DataMember
public var postalCode:String
// @DataMember
public var country:String
// @DataMember
public var phone:String
// @DataMember
public var fax:String
required public init(){}
}
To override the Content-type in your clients, use the HTTP Accept Header, append the .other suffix or ?format=other
The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.
POST /query/customers HTTP/1.1
Host: northwind.netcore.io
Accept: text/jsonl
Content-Type: text/jsonl
Content-Length: length
{"ids":["String"],"countryStartsWith":"String","skip":0,"take":0,"orderBy":"String","orderByDesc":"String","include":"String","fields":"String","meta":{"String":"String"}}
HTTP/1.1 200 OK Content-Type: text/jsonl Content-Length: length {"offset":0,"total":0,"results":[{"id":"String","companyName":"String","contactName":"String","contactTitle":"String","address":"String","city":"String","region":"String","postalCode":"String","country":"String","phone":"String","fax":"String"}],"meta":{"String":"String"},"responseStatus":{"errorCode":"String","message":"String","stackTrace":"String","errors":[{"errorCode":"String","fieldName":"String","message":"String","meta":{"String":"String"}}],"meta":{"String":"String"}}}