Skip to content

jayluxferro/GhanaPostGPS-REST-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GhanaPostGPS REST API

Whitepaper

Read Now


Postman Collection

Postman Collection

Download: GhanaPostGPS-REST-API.postman_collection.json


Docker Instance

Docker Deployment

Details: https://hub.docker.com/r/jayluxferro/ghanapostgps-api

  1. Pull the docker image. docker pull jayluxferro/ghanapostgps-api:latest
  2. Run the docker image. docker run -d -p 9091:9091 -ti jayluxferro/ghanapostgps-api.

NB:

  • Default port for the service is 9091.
  • Base URL: http://localhost:9091

Get Location Coordinates (Latitude/Longitude) from GhanaPostGPS Address.
### API Details
End Point URL: https://ghanapostgps.sperixlabs.org/get-location
Method: POST
API Parameters: address (GhanaPostGPS Address)
Content-Type: application/x-www-form-urlencoded

#### Output/Response:
  1. Location found
{
    "data": {
        "Table": [
            {
                "Area": "NEW KAGYASI",
                "CenterLatitude": 6.650080145273592,
                "CenterLongitude": -1.648700346667856,
                "District": "Kumasi",
                "EastLat": 6.65005768739201,
                "EastLong": -1.6486780409076,
                "GPSName": "AK4849321",
                "NorthLat": 6.65010262239948,
                "NorthLong": -1.6487229566718,
                "PostCode": "AK484",
                "Region": "Ashanti",
                "SouthLat": 6.65005768739201,
                "SouthLong": -1.6487229566718,
                "Street": "Kumasi, Ashanti, GHA",
                "WestLat": 6.65010262239948,
                "WestLong": -1.6486780409076
            }
        ]
    },
    "found": true
}
  1. Location not found
{
    "data": {
        "Table": null
    },
    "found": false
}

Sample Codes

C-Sharp | cURL | Golang | Javascript | NodeJS | PHP | Python | Swift | Java | Ruby | PowerShell


Address: AK-484-9321 or AK4849321


C-Sharp


Code:
var client = new RestClient("https://ghanapostgps.sperixlabs.org/get-location");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("address", "AK-484-9321");
request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

cURL


Code:
curl --location --request POST 'https://ghanapostgps.sperixlabs.org/get-location' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'address=AK-484-9321'

Go


Code:
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://ghanapostgps.sperixlabs.org/get-location"
  method := "POST"

  payload := strings.NewReader("address=AK-484-9321")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}

Javscript


Code:
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

var urlencoded = new URLSearchParams();
urlencoded.append("address", "AK-484-9321");

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: urlencoded,
  redirect: 'follow'
};

fetch("https://ghanapostgps.sperixlabs.org/get-location", requestOptions)
  .then(response => response.json())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

NodeJS


Code:
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://ghanapostgps.sperixlabs.org/get-location',
  'headers': {
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  form: {
    'address': 'AK-484-9321'
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

PHP


Code:
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://ghanapostgps.sperixlabs.org/get-location",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "address=AK-484-9321",
  CURLOPT_HTTPHEADER => array(
    "Content-Type: application/x-www-form-urlencoded"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Python


Code:
import requests

url = "https://ghanapostgps.sperixlabs.org/get-location"

payload = 'address=AK-484-9321'
headers = {
  'Content-Type': 'application/x-www-form-urlencoded'
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.json())

Swift


Code:
import Foundation

var semaphore = DispatchSemaphore (value: 0)

let parameters = "address=AK-484-9321"
let postData =  parameters.data(using: .utf8)

var request = URLRequest(url: URL(string: "https://ghanapostgps.sperixlabs.org/get-location")!,timeoutInterval: Double.infinity)
request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")

request.httpMethod = "POST"
request.httpBody = postData

let task = URLSession.shared.dataTask(with: request) { data, response, error in 
  guard let data = data else {
    print(String(describing: error))
    return
  }
  print(String(data: data, encoding: .utf8)!)
  semaphore.signal()
}

task.resume()
semaphore.wait()

Java


Code:
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "address=AK-484-9321");
Request request = new Request.Builder()
  .url("https://ghanapostgps.sperixlabs.org/get-location")
  .method("POST", body)
  .addHeader("Content-Type", "application/x-www-form-urlencoded")
  .build();
Response response = client.newCall(request).execute();

Ruby


Code:
require "uri"
require "net/http"

url = URI("https://ghanapostgps.sperixlabs.org/get-location")

https = Net::HTTP.new(url.host, url.port);
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/x-www-form-urlencoded"
request.body = "address=AK-484-9321"

response = https.request(request)
puts response.read_body

PowerShell


Code:
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/x-www-form-urlencoded")

$body = "address=AK-484-9321"

$response = Invoke-RestMethod 'https://ghanapostgps.sperixlabs.org/get-location' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json

Get GhanaPostGPS Address from Location Coordinates (Latitude/Longitude).
### API Details
End Point URL: https://ghanapostgps.sperixlabs.org/get-address
Method: POST
API Parameters: lat (latitude), long (longitude)
Content-Type: application/x-www-form-urlencoded

#### Output/Response:
  1. Address found
{
    "data": {
      "Table": [
        {
          "GPSName": "AK4849319",
          "Region": "Ashanti",
          "District": "Kumasi",
          "PostCode": "AK484",
          "NLat": 6.650012752389040,
          "SLat": 6.649967817390580,
          "WLong": -1.648722956671800,
          "Elong": -1.648678040907600,
          "Area": "NEW KAGYASI",
          "Street": "Kumasi, Ashanti, GHA"
        }
      ]
    },
    "found": true
}
  1. Address not found
{
    "data": {
        "Table": null
    },
    "found": false
}

Sample Codes

C-Sharp | cURL | Golang | Javascript | NodeJS | PHP | Python | Swift | Java | Ruby | PowerShell


Address: AK-484-9321 or AK4849321


C-Sharp


Code:
var client = new RestClient("https://ghanapostgps.sperixlabs.org/get-address");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("lat", "6.6500");
request.AddParameter("long", "-1.6487");
request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

cURL


Code:
curl --location --request POST 'https://ghanapostgps.sperixlabs.org/get-address' --form 'lat="6.6500"' --form 'long="-1.647"'

Go


Code:
package main

import (
  "fmt"
  "bytes"
  "mime/multipart"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://ghanapostgps.sperixlabs.org/get-address"
  method := "POST"

  payload := &bytes.Buffer{}
  writer := multipart.NewWriter(payload)
  _ = writer.WriteField("lat", "6.6500")
  _ = writer.WriteField("long", "-1.647")
  err := writer.Close()
  if err != nil {
    fmt.Println(err)
    return
  }


  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

  req.Header.Set("Content-Type", writer.FormDataContentType())
  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}

Javscript


Code:
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

var formdata = new FormData();
formdata.append("lat", "6.6500");
formdata.append("long", "-1.647");

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: formdata
};

fetch("https://ghanapostgps.sperixlabs.org/get-address", requestOptions)
  .then(response => response.json())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

NodeJS


Code:
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://ghanapostgps.sperixlabs.org/get-address',
  'headers': {
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  formData: {
    'lat': '6.6500',
    'long': '-1.647'
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

PHP


Code:
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://ghanapostgps.sperixlabs.org/get-address',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => http_build_query(array('lat' => '6.6500','long' => '-1.647')),
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/x-www-form-urlencoded'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Python


Code:
import requests

url = "https://ghanapostgps.sperixlabs.org/get-address"

payload={'lat': '6.6500', 'long': '-1.647'}
files=[]
headers = {
  'Content-Type': 'application/x-www-form-urlencoded'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.json())

Swift


Code:
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

var semaphore = DispatchSemaphore (value: 0)

let parameters = [
  [
    "key": "lat",
    "value": "6.6500",
    "type": "text"
  ],
  [
    "key": "long",
    "value": "-1.647",
    "type": "text"
  ]] as [[String : Any]]

let boundary = "Boundary-\(UUID().uuidString)"
var body = ""
var error: Error? = nil
for param in parameters {
  if param["disabled"] == nil {
    let paramName = param["key"]!
    body += "--\(boundary)\r\n"
    body += "Content-Disposition:form-data; name=\"\(paramName)\""
    if param["contentType"] != nil {
      body += "\r\nContent-Type: \(param["contentType"] as! String)"
    }
    let paramType = param["type"] as! String
    if paramType == "text" {
      let paramValue = param["value"] as! String
      body += "\r\n\r\n\(paramValue)\r\n"
    } else {
      let paramSrc = param["src"] as! String
      let fileData = try NSData(contentsOfFile:paramSrc, options:[]) as Data
      let fileContent = String(data: fileData, encoding: .utf8)!
      body += "; filename=\"\(paramSrc)\"\r\n"
        + "Content-Type: \"content-type header\"\r\n\r\n\(fileContent)\r\n"
    }
  }
}
body += "--\(boundary)--\r\n";
let postData = body.data(using: .utf8)

var request = URLRequest(url: URL(string: "https://ghanapostgps.sperixlabs.org/get-address")!,timeoutInterval: Double.infinity)
request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.addValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

request.httpMethod = "POST"
request.httpBody = postData

let task = URLSession.shared.dataTask(with: request) { data, response, error in 
  guard let data = data else {
    print(String(describing: error))
    semaphore.signal()
    return
  }
  print(String(data: data, encoding: .utf8)!)
  semaphore.signal()
}

task.resume()
semaphore.wait()

Ruby


Code:
require "uri"
require "net/http"

url = URI("https://ghanapostgps.sperixlabs.org/get-address")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/x-www-form-urlencoded"
form_data = [['lat', '6.6500'],['long', '-1.647']]
request.set_form form_data, 'multipart/form-data'
response = http.request(request)
puts response.read_body

PowerShell


Code:
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/x-www-form-urlencoded")

$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()
$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "lat"
$stringContent = [System.Net.Http.StringContent]::new("6.6500")
$stringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)

$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "long"
$stringContent = [System.Net.Http.StringContent]::new("-1.647")
$stringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)

$body = $multipartContent

$response = Invoke-RestMethod 'https://ghanapostgps.sperixlabs.org/get-address' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json