GET | /config |
---|
import Foundation
import ServiceStack
public class ConfigurationReq : Codable
{
required public init(){}
}
public class Configuration : Entity
{
public var category:String?
public var countries:[String:Country] = [:]
public var listItems:[ListItem] = []
public var listRelationships:[String:String] = [:]
public var sectionElements:[String:[String]] = [:]
public var siteStructure:[String:SiteSection] = [:]
public var version:Int?
public var createdBy:String?
public var dateCreated:Date?
public var updatedBy:String?
public var dateUpdated:Date?
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case category
case countries
case listItems
case listRelationships
case sectionElements
case siteStructure
case version
case createdBy
case dateCreated
case updatedBy
case dateUpdated
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
category = try container.decodeIfPresent(String.self, forKey: .category)
countries = try container.decodeIfPresent([String:Country].self, forKey: .countries) ?? [:]
listItems = try container.decodeIfPresent([ListItem].self, forKey: .listItems) ?? []
listRelationships = try container.decodeIfPresent([String:String].self, forKey: .listRelationships) ?? [:]
sectionElements = try container.decodeIfPresent([String:[String]].self, forKey: .sectionElements) ?? [:]
siteStructure = try container.decodeIfPresent([String:SiteSection].self, forKey: .siteStructure) ?? [:]
version = try container.decodeIfPresent(Int.self, forKey: .version)
createdBy = try container.decodeIfPresent(String.self, forKey: .createdBy)
dateCreated = try container.decodeIfPresent(Date.self, forKey: .dateCreated)
updatedBy = try container.decodeIfPresent(String.self, forKey: .updatedBy)
dateUpdated = try container.decodeIfPresent(Date.self, forKey: .dateUpdated)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if category != nil { try container.encode(category, forKey: .category) }
if countries.count > 0 { try container.encode(countries, forKey: .countries) }
if listItems.count > 0 { try container.encode(listItems, forKey: .listItems) }
if listRelationships.count > 0 { try container.encode(listRelationships, forKey: .listRelationships) }
if sectionElements.count > 0 { try container.encode(sectionElements, forKey: .sectionElements) }
if siteStructure.count > 0 { try container.encode(siteStructure, forKey: .siteStructure) }
if version != nil { try container.encode(version, forKey: .version) }
if createdBy != nil { try container.encode(createdBy, forKey: .createdBy) }
if dateCreated != nil { try container.encode(dateCreated, forKey: .dateCreated) }
if updatedBy != nil { try container.encode(updatedBy, forKey: .updatedBy) }
if dateUpdated != nil { try container.encode(dateUpdated, forKey: .dateUpdated) }
}
}
public class Entity : IEntity, Codable
{
public var id:String?
required public init(){}
}
public class Country : Codable
{
public var name:String?
public var languages:[String:String] = [:]
required public init(){}
}
public class ListItem : Entity
{
public var listId:String?
public var country:String?
public var relatedId:String?
public var code:String?
public var custom:String?
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case listId
case country
case relatedId
case code
case custom
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
listId = try container.decodeIfPresent(String.self, forKey: .listId)
country = try container.decodeIfPresent(String.self, forKey: .country)
relatedId = try container.decodeIfPresent(String.self, forKey: .relatedId)
code = try container.decodeIfPresent(String.self, forKey: .code)
custom = try container.decodeIfPresent(String.self, forKey: .custom)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if listId != nil { try container.encode(listId, forKey: .listId) }
if country != nil { try container.encode(country, forKey: .country) }
if relatedId != nil { try container.encode(relatedId, forKey: .relatedId) }
if code != nil { try container.encode(code, forKey: .code) }
if custom != nil { try container.encode(custom, forKey: .custom) }
}
}
public class SiteSection : Codable
{
public var route:String?
public var `public`:Bool?
public var parent:String?
public var roles:Int?
public var hideFrom:[String] = []
public var order:Int?
required public init(){}
}
To override the Content-type in your clients, use the HTTP Accept Header, append the .jsv suffix or ?format=jsv
The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.
GET /config HTTP/1.1 Host: hcbtas-q-albamfs-api.azurewebsites.net Accept: text/jsv
HTTP/1.1 200 OK Content-Type: text/jsv Content-Length: length { category: String, countries: { String: { name: String, languages: { String: String } } }, listItems: [ { listId: String, country: String, relatedId: String, code: String, custom: String, id: String } ], listRelationships: { String: String }, sectionElements: { String: [ String ] }, siteStructure: { String: { route: String, public: False, parent: String, roles: 0, hideFrom: [ String ], order: 0 } }, version: 0, createdBy: String, dateCreated: 0001-01-01, updatedBy: String, dateUpdated: 0001-01-01, id: String }