1Fetch Client API

<back to all web services

CalculateDistance

The following routes are available for this service:
POST/calculatedistanceCalculate the distance between a list of coordinates
import Foundation
import ServiceStack

public class CalculateDistance : ApiServiceRequest, ILogRequest
{
    /**
    * Array of coordinates
    */
    // @ApiMember(Description="Array of coordinates", IsRequired=true)
    public var coordinates:[Coordinate] = []

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

    private enum CodingKeys : String, CodingKey {
        case coordinates
    }

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

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

public class ApiServiceRequest : IServiceRequest, IHasApiKey, Codable
{
    /**
    * The API Key required for authentication
    */
    // @ApiMember(DataType="string", Description="The API Key required for authentication", IsRequired=true)
    public var apiKey:String

    required public init(){}
}

public class Coordinate : Codable
{
    /**
    * The Latitude
    */
    // @ApiMember(Description="The Latitude", IsRequired=true)
    public var latitude:Double

    /**
    * The Longitude
    */
    // @ApiMember(Description="The Longitude", IsRequired=true)
    public var longitude:Double

    required public init(){}
}

public class CalculateDistanceResponse : ApiServiceResponse
{
    /**
    * A list of the distances between each point, returned in order that the points were provided
    */
    // @ApiMember(Description="A list of the distances between each point, returned in order that the points were provided")
    public var pointDistances:[Double] = []

    /**
    * The total distance between all points
    */
    // @ApiMember(Description="The total distance between all points")
    public var totalDistance:Double

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

    private enum CodingKeys : String, CodingKey {
        case pointDistances
        case totalDistance
    }

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

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

public class ApiServiceResponse : IServiceResponse, Codable
{
    /**
    * Information about the response.
    */
    // @ApiMember(Description="Information about the response.", IsRequired=true)
    public var Description:String

    /**
    * Heading or summary of the response.
    */
    // @ApiMember(Description="Heading or summary of the response.", IsRequired=true)
    public var heading:String

    /**
    * Did the intended operation for this response complete successfully?
    */
    // @ApiMember(DataType="boolean", Description="Did the intended operation for this response complete successfully?", IsRequired=true)
    public var wasSuccessful:Bool

    required public init(){}
}


Swift CalculateDistance DTOs

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

HTTP + OTHER

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

POST /calculatedistance HTTP/1.1 
Host: 1fetch.api.client.prod.86degrees.com 
Accept: text/jsonl
Content-Type: text/jsonl
Content-Length: length

{"Coordinates":[{"Latitude":0,"Longitude":0}],"ApiKey":"String"}
HTTP/1.1 200 OK
Content-Type: text/jsonl
Content-Length: length

{"PointDistances":[0],"TotalDistance":0,"Description":"String","Heading":"String","WasSuccessful":false}