MyApp

<back to all web services

QueryGameItem

Game
import Foundation
import ServiceStack

public class QueryGameItem : QueryDb<GameItem>
{
    public var name:String

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

    private enum CodingKeys : String, CodingKey {
        case name
    }

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

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

public class GameItem : AuditBase
{
    // @StringLength(50)
    public var name:String

    public var imageUrl:String
    // @StringLength(Int32.max)
    public var Description:String

    public var dateAdded:Date

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

    private enum CodingKeys : String, CodingKey {
        case name
        case imageUrl
        case Description
        case dateAdded
    }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let container = try decoder.container(keyedBy: CodingKeys.self)
        name = try container.decodeIfPresent(String.self, forKey: .name)
        imageUrl = try container.decodeIfPresent(String.self, forKey: .imageUrl)
        Description = try container.decodeIfPresent(String.self, forKey: .Description)
        dateAdded = try container.decodeIfPresent(Date.self, forKey: .dateAdded)
    }

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

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

    required public init(){}
}


Swift QueryGameItem DTOs

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

HTTP + JSV

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

POST /jsv/reply/QueryGameItem HTTP/1.1 
Host: blazor-gallery.servicestack.net 
Accept: text/jsv
Content-Type: text/jsv
Content-Length: length

{
	name: String,
	skip: 0,
	take: 0,
	orderBy: String,
	orderByDesc: String,
	include: String,
	fields: String,
	meta: 
	{
		String: String
	}
}
HTTP/1.1 200 OK
Content-Type: text/jsv
Content-Length: length

{
	offset: 0,
	total: 0,
	results: 
	[
		{
			name: String,
			imageUrl: String,
			description: String,
			dateAdded: 0001-01-01,
			createdDate: 0001-01-01,
			createdBy: String,
			modifiedDate: 0001-01-01,
			modifiedBy: String,
			deletedDate: 0001-01-01,
			deletedBy: String
		}
	],
	meta: 
	{
		String: String
	},
	responseStatus: 
	{
		errorCode: String,
		message: String,
		stackTrace: String,
		errors: 
		[
			{
				errorCode: String,
				fieldName: String,
				message: String,
				meta: 
				{
					String: String
				}
			}
		],
		meta: 
		{
			String: String
		}
	}
}