MyApp

<back to all web services

QueryMediaTypes

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

public class QueryMediaTypes : QueryDb<MediaTypes>, IGet
{
    public var mediaTypeId:Int?

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

    private enum CodingKeys : String, CodingKey {
        case mediaTypeId
    }

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

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

public class MediaTypes : Codable
{
    public var mediaTypeId:Int
    public var name:String

    required public init(){}
}

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

    required public init(){}
}


Swift QueryMediaTypes 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 /mediatypes 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":[{"mediaTypeId":0,"name":"String"}],"meta":{"String":"String"},"responseStatus":{"errorCode":"String","message":"String","stackTrace":"String","errors":[{"errorCode":"String","fieldName":"String","message":"String","meta":{"String":"String"}}],"meta":{"String":"String"}}}