curl -X POST "https://trackservice.trackroad.com/rest/Route" \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_TRACKSERVICEKEY" \
-d @route-request.json
using System.Net.Http;
using System.Text;
var url = "https://trackservice.trackroad.com/rest/Route";
using var http = new HttpClient();
http.DefaultRequestHeaders.Add("X-API-Key", "YOUR_TRACKSERVICEKEY");
var json = @"{
""Locations"": [
{ ""Name"": ""Start"", ""LatLong"": { ""Latitude"": 37.7946, ""Longitude"": -122.3950 }, ""LocationType"": 1 },
{ ""Name"": ""Stop A"", ""LatLong"": { ""Latitude"": 37.7897, ""Longitude"": -122.4011 }, ""LocationType"": 0 },
{ ""Name"": ""Finish"", ""LatLong"": { ""Latitude"": 37.7810, ""Longitude"": -122.4110 }, ""LocationType"": 2 }
],
""RouteOptions"": { ""RoutingService"": 2, ""DistanceUnit"": 0, ""RouteOptimize"": 0, ""Culture"": ""en-US"", ""ZoomLevel"": 0 }
}";
using var content = new StringContent(json, Encoding.UTF8, "application/json");
var resp = await http.PostAsync(url, content);
Console.WriteLine(await resp.Content.ReadAsStringAsync());
const url = "https://trackservice.trackroad.com/rest/Route";
const payload = {
Locations: [
{ Name: "Start", LatLong: { Latitude: 37.7946, Longitude: -122.3950 }, LocationType: 1 },
{ Name: "Stop A", LatLong: { Latitude: 37.7897, Longitude: -122.4011 }, LocationType: 0 },
{ Name: "Finish", LatLong: { Latitude: 37.7810, Longitude: -122.4110 }, LocationType: 2 }
],
RouteOptions: { RoutingService: 2, DistanceUnit: 0, RouteOptimize: 0, Culture: "en-US", ZoomLevel: 0 }
};
const res = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": "YOUR_TRACKSERVICEKEY"
},
body: JSON.stringify(payload)
});
console.log(await res.text());
import okhttp3.*;
public class Main {
public static void main(String[] args) throws Exception {
OkHttpClient client = new OkHttpClient();
String json = "{"
+ "\"Locations\":["
+ "{\"Name\":\"Start\",\"LatLong\":{\"Latitude\":37.7946,\"Longitude\":-122.3950},\"LocationType\":1},"
+ "{\"Name\":\"Stop A\",\"LatLong\":{\"Latitude\":37.7897,\"Longitude\":-122.4011},\"LocationType\":0},"
+ "{\"Name\":\"Finish\",\"LatLong\":{\"Latitude\":37.7810,\"Longitude\":-122.4110},\"LocationType\":2}"
+ "],"
+ "\"RouteOptions\":{\"RoutingService\":2,\"DistanceUnit\":0,\"RouteOptimize\":0,\"Culture\":\"en-US\",\"ZoomLevel\":0}"
+ "}";
RequestBody body = RequestBody.create(json, MediaType.parse("application/json"));
Request request = new Request.Builder()
.url("https://trackservice.trackroad.com/rest/Route")
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("X-API-Key", "YOUR_TRACKSERVICEKEY")
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println(response.body().string());
}
}
}
import requests
url = "https://trackservice.trackroad.com/rest/Route"
headers = {
"Content-Type": "application/json",
"X-API-Key": "YOUR_TRACKSERVICEKEY"
}
payload = {
"Locations": [
{ "Name": "Start", "LatLong": { "Latitude": 37.7946, "Longitude": -122.3950 }, "LocationType": 1 },
{ "Name": "Stop A", "LatLong": { "Latitude": 37.7897, "Longitude": -122.4011 }, "LocationType": 0 },
{ "Name": "Finish", "LatLong": { "Latitude": 37.7810, "Longitude": -122.4110 }, "LocationType": 2 }
],
"RouteOptions": { "RoutingService": 2, "DistanceUnit": 0, "RouteOptimize": 0, "Culture": "en-US", "ZoomLevel": 0 }
}
r = requests.post(url, headers=headers, json=payload)
print(r.text)
<?php
$url = "https://trackservice.trackroad.com/rest/Route";
$payload = json_encode([
"Locations" => [
[ "Name" => "Start", "LatLong" => [ "Latitude" => 37.7946, "Longitude" => -122.3950 ], "LocationType" => 1 ],
[ "Name" => "Stop A", "LatLong" => [ "Latitude" => 37.7897, "Longitude" => -122.4011 ], "LocationType" => 0 ],
[ "Name" => "Finish", "LatLong" => [ "Latitude" => 37.7810, "Longitude" => -122.4110 ], "LocationType" => 2 ]
],
"RouteOptions" => [ "RoutingService" => 2, "DistanceUnit" => 0, "RouteOptimize" => 0, "Culture" => "en-US", "ZoomLevel" => 0 ]
]);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: YOUR_TRACKSERVICEKEY"
],
CURLOPT_POSTFIELDS => $payload
]);
echo curl_exec($ch);
curl_close($ch);
require "net/http"
require "json"
require "uri"
uri = URI("https://trackservice.trackroad.com/rest/Route")
payload = {
Locations: [
{ Name: "Start", LatLong: { Latitude: 37.7946, Longitude: -122.3950 }, LocationType: 1 },
{ Name: "Stop A", LatLong: { Latitude: 37.7897, Longitude: -122.4011 }, LocationType: 0 },
{ Name: "Finish", LatLong: { Latitude: 37.7810, Longitude: -122.4110 }, LocationType: 2 }
],
RouteOptions: { RoutingService: 2, DistanceUnit: 0, RouteOptimize: 0, Culture: "en-US", ZoomLevel: 0 }
}
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
req = Net::HTTP::Post.new(uri.request_uri)
req["Content-Type"] = "application/json"
req["X-API-Key"] = "YOUR_TRACKSERVICEKEY"
req.body = JSON.generate(payload)
res = http.request(req)
puts res.body
package main
import (
"bytes"
"fmt"
"net/http"
)
func main() {
url := "https://trackservice.trackroad.com/rest/Route"
body := []byte(`{
"Locations": [
{ "Name": "Start", "LatLong": { "Latitude": 37.7946, "Longitude": -122.3950 }, "LocationType": 1 },
{ "Name": "Stop A", "LatLong": { "Latitude": 37.7897, "Longitude": -122.4011 }, "LocationType": 0 },
{ "Name": "Finish", "LatLong": { "Latitude": 37.7810, "Longitude": -122.4110 }, "LocationType": 2 }
],
"RouteOptions": { "RoutingService": 2, "DistanceUnit": 0, "RouteOptimize": 0, "Culture": "en-US", "ZoomLevel": 0 }
}`)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-API-Key", "YOUR_TRACKSERVICEKEY")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var buf bytes.Buffer
buf.ReadFrom(resp.Body)
fmt.Println(buf.String())
}
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
fun main() {
val client = OkHttpClient()
val url = "https://trackservice.trackroad.com/rest/Route"
val json = """
{
"Locations": [
{ "Name": "Start", "LatLong": { "Latitude": 37.7946, "Longitude": -122.3950 }, "LocationType": 1 },
{ "Name": "Stop A", "LatLong": { "Latitude": 37.7897, "Longitude": -122.4011 }, "LocationType": 0 },
{ "Name": "Finish", "LatLong": { "Latitude": 37.7810, "Longitude": -122.4110 }, "LocationType": 2 }
],
"RouteOptions": { "RoutingService": 2, "DistanceUnit": 0, "RouteOptimize": 0, "Culture": "en-US", "ZoomLevel": 0 }
}
""".trimIndent()
val body = json.toRequestBody("application/json".toMediaType())
val request = Request.Builder()
.url(url)
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("X-API-Key", "YOUR_TRACKSERVICEKEY")
.build()
client.newCall(request).execute().use { resp ->
println(resp.body?.string())
}
}
#include <stdio.h>
#include <string.h>
#include <curl/curl.h>
int main(void) {
CURL *curl = curl_easy_init();
if (!curl) return 1;
const char *url = "https://trackservice.trackroad.com/rest/Route";
const char *json =
"{"
"\"Locations\":["
"{\"Name\":\"Start\",\"LatLong\":{\"Latitude\":37.7946,\"Longitude\":-122.3950},\"LocationType\":1},"
"{\"Name\":\"Stop A\",\"LatLong\":{\"Latitude\":37.7897,\"Longitude\":-122.4011},\"LocationType\":0},"
"{\"Name\":\"Finish\",\"LatLong\":{\"Latitude\":37.7810,\"Longitude\":-122.4110},\"LocationType\":2}"
"],"
"\"RouteOptions\":{\"RoutingService\":2,\"DistanceUnit\":0,\"RouteOptimize\":0,\"Culture\":\"en-US\",\"ZoomLevel\":0}"
"}";
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "X-API-Key: YOUR_TRACKSERVICEKEY");
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
CURLcode res = curl_easy_perform(curl);
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
return (res == CURLE_OK) ? 0 : 1;
}
#include <curl/curl.h>
int main() {
CURL* curl = curl_easy_init();
if (!curl) return 1;
const char* url = "https://trackservice.trackroad.com/rest/Route";
const char* json =
"{"
"\"Locations\":["
"{\"Name\":\"Start\",\"LatLong\":{\"Latitude\":37.7946,\"Longitude\":-122.3950},\"LocationType\":1},"
"{\"Name\":\"Stop A\",\"LatLong\":{\"Latitude\":37.7897,\"Longitude\":-122.4011},\"LocationType\":0},"
"{\"Name\":\"Finish\",\"LatLong\":{\"Latitude\":37.7810,\"Longitude\":-122.4110},\"LocationType\":2}"
"],"
"\"RouteOptions\":{\"RoutingService\":2,\"DistanceUnit\":0,\"RouteOptimize\":0,\"Culture\":\"en-US\",\"ZoomLevel\":0}"
"}";
struct curl_slist* headers = nullptr;
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "X-API-Key: YOUR_TRACKSERVICEKEY");
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
CURLcode res = curl_easy_perform(curl);
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
return (res == CURLE_OK) ? 0 : 1;
}
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSURL *url = [NSURL URLWithString:@"https://trackservice.trackroad.com/rest/Route"];
NSDictionary *payload = @{
@"Locations": @[
@{@"Name":@"Start", @"LatLong":@{@"Latitude":@37.7946, @"Longitude":@-122.3950}, @"LocationType":@1},
@{@"Name":@"Stop A", @"LatLong":@{@"Latitude":@37.7897, @"Longitude":@-122.4011}, @"LocationType":@0},
@{@"Name":@"Finish", @"LatLong":@{@"Latitude":@37.7810, @"Longitude":@-122.4110}, @"LocationType":@2}
],
@"RouteOptions": @{@"RoutingService":@2, @"DistanceUnit":@0, @"RouteOptimize":@0, @"Culture":@"en-US", @"ZoomLevel":@0}
};
NSData *body = [NSJSONSerialization dataWithJSONObject:payload options:0 error:nil];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
req.HTTPMethod = @"POST";
[req setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[req setValue:@"YOUR_TRACKSERVICEKEY" forHTTPHeaderField:@"X-API-Key"];
req.HTTPBody = body;
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:req
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) { NSLog(@"%@", error); }
else { NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); }
dispatch_semaphore_signal(sema);
}];
[task resume];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
}
return 0;
}
import Foundation
let url = URL(string: "https://trackservice.trackroad.com/rest/Route")!
let payload: [String: Any] = [
"Locations": [
["Name": "Start", "LatLong": ["Latitude": 37.7946, "Longitude": -122.3950], "LocationType": 1],
["Name": "Stop A", "LatLong": ["Latitude": 37.7897, "Longitude": -122.4011], "LocationType": 0],
["Name": "Finish", "LatLong": ["Latitude": 37.7810, "Longitude": -122.4110], "LocationType": 2]
],
"RouteOptions": ["RoutingService": 2, "DistanceUnit": 0, "RouteOptimize": 0, "Culture": "en-US", "ZoomLevel": 0]
]
let body = try JSONSerialization.data(withJSONObject: payload, options: [])
var req = URLRequest(url: url)
req.httpMethod = "POST"
req.setValue("application/json", forHTTPHeaderField: "Content-Type")
req.setValue("YOUR_TRACKSERVICEKEY", forHTTPHeaderField: "X-API-Key")
req.httpBody = body
let sema = DispatchSemaphore(value: 0)
URLSession.shared.dataTask(with: req) { data, response, error in
if let error = error { print(error) }
else if let data = data { print(String(data: data, encoding: .utf8) ?? "") }
sema.signal()
}.resume()
sema.wait()