Pecuario.Backend

<back to all web services

GetMeasurementUnits

The following routes are available for this service:
GET/api/v1/utils/units
import Foundation
import ServiceStack

public class GetMeasurementUnits : IGet, Codable
{
    required public init(){}
}

public class GetMeasurementUnitsResponse : BaseResponse
{
    public var units:[MeasurementUnit] = []

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

    private enum CodingKeys : String, CodingKey {
        case units
    }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let container = try decoder.container(keyedBy: CodingKeys.self)
        units = try container.decodeIfPresent([MeasurementUnit].self, forKey: .units) ?? []
    }

    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        if units.count > 0 { try container.encode(units, forKey: .units) }
    }
}

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 MeasurementUnit : Codable
{
    public var id:Int
    // @Required()
    // @StringLength(10)
    public var code:String?

    // @Required()
    // @StringLength(100)
    public var name:String?

    required public init(){}
}


Swift GetMeasurementUnits 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.

GET /api/v1/utils/units HTTP/1.1 
Host: pecuario-backend.develsystems.com 
Accept: text/jsv
HTTP/1.1 200 OK
Content-Type: text/jsv
Content-Length: length

{
	units: 
	[
		{
			id: 0,
			code: String,
			name: String
		}
	]
}