MyApp

<back to all web services

QueryTracks

Media
The following routes are available for this service:
GET/tracks
GET/tracks/{TrackId}
import Foundation
import ServiceStack

public class QueryTracks : QueryDb<Tracks>, IGet
{
    public var trackId:Int?
    public var nameContains:String

    required public init(){ super.init() }

    private enum CodingKeys : String, CodingKey {
        case trackId
        case nameContains
    }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let container = try decoder.container(keyedBy: CodingKeys.self)
        trackId = try container.decodeIfPresent(Int.self, forKey: .trackId)
        nameContains = try container.decodeIfPresent(String.self, forKey: .nameContains)
    }

    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        if trackId != nil { try container.encode(trackId, forKey: .trackId) }
        if nameContains != nil { try container.encode(nameContains, forKey: .nameContains) }
    }
}

public class Tracks : Codable
{
    public var trackId:Int
    // @Required()
    public var name:String?

    public var albumId:Int?
    public var mediaTypeId:Int
    public var genreId:Int?
    public var composer:String
    public var milliseconds:Int
    public var bytes:Int?
    public var unitPrice:Double

    required public init(){}
}

public class Todo : Codable
{
    public var id:Int
    public var text:String
    public var isFinished:Bool

    required public init(){}
}


Swift QueryTracks DTOs

To override the Content-type in your clients, use the HTTP Accept Header, append the .json suffix or ?format=json

To embed the response in a jsonp callback, append ?callback=myCallback

HTTP + JSON

The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.

GET /tracks HTTP/1.1 
Host: blazor-gallery.servicestack.net 
Accept: application/json
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: length

{"offset":0,"total":0,"results":[{"trackId":0,"name":"String","albumId":0,"mediaTypeId":0,"genreId":0,"composer":"String","milliseconds":0,"bytes":0,"unitPrice":0}],"meta":{"String":"String"},"responseStatus":{"errorCode":"String","message":"String","stackTrace":"String","errors":[{"errorCode":"String","fieldName":"String","message":"String","meta":{"String":"String"}}],"meta":{"String":"String"}}}