GET | /customers | ||
---|---|---|---|
GET | /customers/{CustomerId} |
import Foundation
import ServiceStack
public class QueryChinookCustomers : QueryDb<Customers>, IGet
{
public var customerId:Int?
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case customerId
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
customerId = try container.decodeIfPresent(Int.self, forKey: .customerId)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if customerId != nil { try container.encode(customerId, forKey: .customerId) }
}
}
public class Customers : Codable
{
public var customerId:Int
// @Required()
public var firstName:String?
// @Required()
public var lastName:String?
public var company:String
public var address:String
public var city:String
public var state:String
public var country:String
public var postalCode:String
public var phone:String
public var fax:String
// @Required()
public var email:String?
public var supportRepId:Int?
required public init(){}
}
public class Todo : Codable
{
public var id:Int
public var text:String
public var isFinished:Bool
required public init(){}
}
Swift QueryChinookCustomers DTOs
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.
GET /customers HTTP/1.1 Host: blazor-gallery.servicestack.net Accept: text/jsonl
HTTP/1.1 200 OK Content-Type: text/jsonl Content-Length: length {"offset":0,"total":0,"results":[{"customerId":0,"firstName":"String","lastName":"String","company":"String","address":"String","city":"String","state":"String","country":"String","postalCode":"String","phone":"String","fax":"String","email":"String","supportRepId":0}],"meta":{"String":"String"},"responseStatus":{"errorCode":"String","message":"String","stackTrace":"String","errors":[{"errorCode":"String","fieldName":"String","message":"String","meta":{"String":"String"}}],"meta":{"String":"String"}}}