| GET | /api/v1/utils/regions | ||
|---|---|---|---|
| GET | /api/v1/utils/regions/{CountryId} |
import Foundation
import ServiceStack
public class GetRegionsByCountry : IGet, Codable
{
public var countryId:Int?
required public init(){}
}
public class GetRegionsByCountryResponse : BaseResponse
{
public var regions:[Region] = []
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case regions
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
regions = try container.decodeIfPresent([Region].self, forKey: .regions) ?? []
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if regions.count > 0 { try container.encode(regions, forKey: .regions) }
}
}
public class BaseResponse : Codable
{
public var status:Status
required public init(){}
}
public class Status : Codable
{
public var message:String
public var statusCode:Int
required public init(){}
}
public class Region : Codable
{
public var id:Int
// @References(typeof(Country))
public var countryId:Int
// @Required()
// @StringLength(200)
public var name:String?
required public init(){}
}
Swift GetRegionsByCountry DTOs
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 /api/v1/utils/regions HTTP/1.1 Host: pecuario-backend.develsystems.com Accept: text/jsv
HTTP/1.1 200 OK
Content-Type: text/jsv
Content-Length: length
{
regions:
[
{
id: 0,
countryId: 0,
name: String
}
]
}